Solved

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

Posted on 2007-04-06
7
393 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
  • 4
7 Comments
 
LVL 14

Expert Comment

by:existenz2
Comment Utility
0
 
LVL 1

Author Comment

by:psyche6
Comment Utility
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
Comment Utility
I found this article:
    http://discuss.joelonsoftware.com/default.asp?dotnet.12.302317.3
and thought FOR SURE
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:psyche6
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
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 video discusses moving either the default database or any database to a new volume.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now