[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Error calling .Net lib from VB script, calling from VB6 executable works

Posted on 2007-04-06
7
Medium Priority
?
407 Views
Last Modified: 2013-11-18
When I create a C# .Net library (Framework 2.0 and Visual Studio 2005) and expose it to com, it works great from a Visual Basic 6 client but doesn't work from a VB script client (such as Excel).

The error message from Microsoft Visual Basic in Excel is:
Run-time error '-2147024894(800070002)';
File or assembly name TestCallingDotNetFromCom, or one of its dependencies, was not found.

Here's the C# library code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TestCallingDotNetFromCom
{
    public interface iTestStuff
    {
        string SayHello();
    }

    [ClassInterface(ClassInterfaceType.None)]
    public class TestStuff : iTestStuff
    {
        public TestStuff()
        {
        }

        public string SayHello()
        {
            return "Hello there";
        }
    }
}

It's complied as a strong-name assembly with the Make assembly COM-Visible checkbox checked. I copy the library to another machine (XP Professional) and register it as:
regasm TestCallingDotNetFromCom.dll /tlb
This creates the type library and registers both the type library and the library. Then I copy the library to the GAC.

I open up the Visual Basic editor in Excel (XP version) and set a reference to TestCallingDotNetFromCom. Examining it from the Object Browser, it looks fine. I add a module with the code:
Sub Test()
    Dim obj As New TestCallingDotNetFromCom.TestStuff, _
        s As String
    s = obj.SayHello
    Set obj = Nothing
End Sub
When I run the code I get the error mentioned above.

HOWEVER, I use Visual Basic 6 to create an executable with EXACTLY  the same code, then copy the exe to the test machine and run it, it works perfectly!

What's the difference between calling a com callable .Net library from Visual Basic 6 and Visual Basic script in Excel?

Appreciate any help!
0
Comment
Question by:psyche6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 18870578
0
 
LVL 1

Author Comment

by:psyche6
ID: 18877493
Thanks to existenz2, but that's not it.

I am carefully registering the library:
    regasm TestCallingDotNetFromCom.dll /tlb
which both creates the type library AND registers the library and the new type library in one pass.

I am also adding the library to the GAC:
    gacutil /i TestCallingDotNetFromCom.dll
and checking the \Windows\assembly folder afterwards.

As I mentioned, a compiled VB6 .exe that uses TestCallingDotNetFromCom as a com server works fine when copied to the test PC (in a different folder, of course, than the TestCallingDotNetFromCom.dll file so as to be sure that the .exe is using it from the GAC). The compiled VB6 .exe actually accesses the library twice - once using design time linking and once using run time (CreateObject) linking. However, when I try to access the library from VB script within Excel, I still get the same error mentioned in my first post.
0
 
LVL 1

Author Comment

by:psyche6
ID: 18878105
I found this article:
    http://discuss.joelonsoftware.com/default.asp?dotnet.12.302317.3
and thought FOR SURE
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:psyche6
ID: 18878169
I found this article
    http://discuss.joelonsoftware.com/default.asp?dotnet.12.302317.3
and thought FOR SURE I'd found the answer. Unfortunately, it didn't work. Still, this article is really intriguing - I think the answer will be something similar.
0
 
LVL 1

Author Comment

by:psyche6
ID: 18919697
After a technical support call to Microsoft, the answer is that there is a bug with VBA and/or Office linking to the wrong version of the framework if more than one version of the framework is loaded.

Here's a link to the relavent Microsoft article:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;908002

Note: this is not a fix that you load directly onto the client machine. Rather it is an update to Visual Studio 2005 which gives you a resource that you include as a prerequisite in a Visual Studio 2005 setup project that you deploy on the client machine. You can include only this resource in the setup project if you only want to apply the fix to the client machine, or you may include the resource in the setup project of an application or library you are deploying that will require this fix.

This question is closed.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19280642
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question