Solved

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

Posted on 2007-04-06
7
399 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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