4
votes

I wrote a dll in c#.net that calls another third party .NET dll within the application. This works fine when I tested it with a console application written in c#.NET as well using the code below:

 Assembly u = Assembly.LoadFrom(dllLocation);
 Type t = u.GetType("MyLIB.CLass");
 MethodInfo m = t.GetMethod("Method");
 object[] myparam = new object[1];
 myparam[0] = fileLocation;
 result = (string)m.Invoke(null, myparam);

Please note that some files are loaded within the location where the dll was initially loaded as well using:

  string path = Assembly.GetExecutingAssembly().Location;
  path = Path.GetDirectoryName(path);

But the issue is that when I tried to call it using VB6, I get an error that it cannot load the third party dll. Please help as I seem not to know what's going on.

2
What is the exact error? And have you checked that it is looking in the correct location? - MarkJ
The exact error is "it cannot find the third party dll or one of it's dependencies are missing". Please how can I check if it is looking in the current location in VB6? - Jay
looks like you need to check with the vendor who supplied you the third party dll and ask for COM interop support. - Turbot

2 Answers

6
votes

I would thought to give you more detail, in order .NET Assembly expose to COM

you need to generate the tbl - type library

using RegAsm /tlb: MyLIB.tlb MyLIB.dll

There are Guidelines to expose .NET Types to COM and make sure you cope with that. such as declare ComVisibleAttribute , require a public default constructor to be visible to COM , such are in

you can refer that in How to call a Visual Basic .NET or Visual Basic 2005 assembly from Visual Basic 6.0

3
votes

You need to specify the ComVisibleAttribute on the assembly in order to call it from VB6.