Interop call

G

Guest

I have a vb6 Exe. I need to call a C# dll's methods from the VB Exe. I have
used RegAsm to register the C# dll. If the VB6 Exe and the C# dll are in the
same folder, then everything is fine. But I want to place them in different
folders. When I place the VB6 Exe in a folder called 'A' and the C# dll in a
folder called 'B', the VB6 Exe throws the following error when it tries to
invoke the c# dll's method.

-2147024894 - Automation error.
The system cannot find the file specified.

What do I have to do to make it work?
 
V

Vadym Stetsyak

Put the asm in the new folder and reregister it. When you register dll,
actually you register a COM component ( VB6 sees your dll as a COM ).
Registration means that appropriate aliases a placed to the windows
registry. You can think of alias as
GUID <-> assembly path.
 
W

Willy Denoyette [MVP]

Tim said:
I have a vb6 Exe. I need to call a C# dll's methods from the VB Exe. I have
used RegAsm to register the C# dll. If the VB6 Exe and the C# dll are in
the
same folder, then everything is fine. But I want to place them in
different
folders. When I place the VB6 Exe in a folder called 'A' and the C# dll in
a
folder called 'B', the VB6 Exe throws the following error when it tries to
invoke the c# dll's method.

-2147024894 - Automation error.
The system cannot find the file specified.

What do I have to do to make it work?

Use regasm with the /codebase option. Another option is to install the
assembly in the GAC.

Willy.
 
W

Willy Denoyette [MVP]

Yes, but you should register the assembly with the /codebase option set or
you have to install the assembly in the GAC. Remember that your assembly
classes are no COM objects and they don't become COM objects even after you
register them. What you do by running regasm is effectively registering
mscoree.dll as COM server, and it's up to this server to load the assembly
(and the CLR). To make it possible to load the assembly the assembly must be
stored in the GAC, or the assembly path must be registered as well, this is
achieved by the /codebase option.


Willy.
 
G

Guest

Thank you for the response.

I tried the codebase option. But, now I am getting error at the next stage.

The process that I followed is as follows:

To explain in detail, the VB Exe refers a C# dll say 'A.dll'. 'A.dll' in
turn references another c# dll 'B.dll' and a C# exe 'C.exe'. I used VS2005
IDE to generate a strong name for 'A.Dll' , B.Dll and C.exe. I have used the
same strong name key file - say abc.snk. Is that okay or do I need to have
separate strong name key files for each of the assemblies?

Then I used the RegAsm utility with /Codebase option and /tlb option to make
the necessary registry entries and generate the tlb file.

Then I re-compiled the VB exe. When I run the VB exe from the same folder as
the Managed Dll's, everything works fine.

But, if I place the VB Exe in a folder say 'FolderA' and the managed
binaries in a different folder say 'FolderB', it throws an error.
The VB exe invokes methods on A.dll, A.dll in turn accesses methods on B.dll.

At that time, error occurs.
Error: -2147024894. Could not load file or assembly 'B', version=1.0.0.0,
Culture=neutral, PublicKeyToken=b941z50222f55471' or one of its dependencies.
The system cannot find the file specified.

And as per the requirement, I shouldn't place my modules in the GAC.

Where Am I going wrong?
 
W

Willy Denoyette [MVP]

Tim said:
Thank you for the response.

I tried the codebase option. But, now I am getting error at the next
stage.

The process that I followed is as follows:

To explain in detail, the VB Exe refers a C# dll say 'A.dll'. 'A.dll' in
turn references another c# dll 'B.dll' and a C# exe 'C.exe'. I used VS2005
IDE to generate a strong name for 'A.Dll' , B.Dll and C.exe. I have used
the
same strong name key file - say abc.snk. Is that okay or do I need to have
separate strong name key files for each of the assemblies?

Then I used the RegAsm utility with /Codebase option and /tlb option to
make
the necessary registry entries and generate the tlb file.

Then I re-compiled the VB exe. When I run the VB exe from the same folder
as
the Managed Dll's, everything works fine.

But, if I place the VB Exe in a folder say 'FolderA' and the managed
binaries in a different folder say 'FolderB', it throws an error.
The VB exe invokes methods on A.dll, A.dll in turn accesses methods on
B.dll.

At that time, error occurs.
Error: -2147024894. Could not load file or assembly 'B', version=1.0.0.0,
Culture=neutral, PublicKeyToken=b941z50222f55471' or one of its
dependencies.
The system cannot find the file specified.

And as per the requirement, I shouldn't place my modules in the GAC.

Where Am I going wrong?

By using /codebase you solved the COM issue, that is, the VB client can load
the 'assembly' through COM's native DLL load infrastruture (registry
based), but now you encounter an issue with the pure .net assembly loader
which doesn' use the registry to finf the assembly (it uses fusion). If the
GAC is not an option you should place the .NET assemblies in the path of the
client.
For more info on how .NET searches for assemblies, search MSDN for "How the
Runtime Locates Assemblies "

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top