4

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.

3
  • What is the exact error? And have you checked that it is looking in the correct location? Commented Sep 18, 2012 at 7:01
  • 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? Commented Sep 18, 2012 at 7:18
  • looks like you need to check with the vendor who supplied you the third party dll and ask for COM interop support. Commented Sep 18, 2012 at 13:15

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

3 Comments

I have specified the necessary ComVisibleAttribute to true, generated the type library and also registered the assembly but recall that my .NET dll references a third party dll. That's where the error pops from, but there's no way I could specify the ComVisibleAttribute for the third party dll. Is there any other way around it?
You have marked this as the answer, but your comment suggests you wanted the VB6 code to access the third party DLL directly. Just confirming this is not possible, but you can always add code with the ComVisibleAttribute to the DLL you do have control over that passes the calls straight on to the third party DLL.
in this case , you couldn't access the .NET Dll reference directly but you can create interfaces and explicit implement them in .NET classes, and generate the COM interop for your VB6 reference. the link I posted provides the guidelines.
3

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

1 Comment

I have specified the necessary ComVisibleAttribute to true but recall that my .NET dll references a third party dll. That's where the error pops from, but there's no way I could specify the ComVisibleAttribute for the third party dll. Is there any other way around it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.