Search This Blog

Friday, July 17, 2009

VB6 App with C# COM object

VB6 project using C# COM Assembly
-2147024896 (80070002) Automation error The System cannot find file specified

I get this very thing...

from MSDN forum

Question:
i'm having problems running the vb6 app, and the error occurs when i make the form show. i've followed the instructions from the help file and still the problem arises everytime.

here's another weird thing, when i added the interop form to an existing vb6 application, it was ok when run inside the ide. when i compiled this to an .exe file, the error happened. i also tried creating fresh vb6 app and it worked, so any ideas on this issue? thanks.


Answer:
1) Strongly name Assemblies.
   sn -k TestKeyPair.snk
2) Add TestKeyPair.snk to project(s).
3) Edit AssemblyInfo.cs
A) Make assembly is versioned
[assembly: AssemblyVersion("1.0.0.0")]
b) Add [assembly: AssemblyKeyFile("TestKeyPair.snk")]
4) Add Assembly to GAC
gacutil /i MyInterop.dll
- Make sure all Assembly DLLS has been
5) Regasm Assembly and expose COM use /codebase
REGASM MyInterop.dll /tlb:com.MyInterop.tlb /codebase
Better Answer:
1) Strongly name Assemblies.
   sn -k TestKeyPair.snk
2) Add TestKeyPair.snk to project(s).
3) Edit AssemblyInfo.cs
A) Make assembly is versioned
[assembly: AssemblyVersion("1.0.0.0")]
b) Add [assembly: AssemblyKeyFile("TestKeyPair.snk")]
4) Copied all related assemblies local to folder containing VB6 project
5) Run from this folder: tlbexp sampleDLL.dll /out:sampleDLL.tlb
6) run from this folder: regasm sampleDLL.dll /tlb:sampleDLL.tlb
7) Open VB6 project and reference to sampleDLL.tlb is local to project.

No comments: