Solved

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

Posted on 2007-04-06
7
398 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
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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