VB6 application using COM Interop works fine in IDE, but compiled EXE crashes

I am currently working on an application in VB6 that uses COM Interop libraries written in C # using the .NET 2.0 framework.

I used regasm.exe to register tlb files from DLL.NET using the / codebase switch. Then I was able to successfully create and run the application in the VB6 environment without any problems. The .NET code uses the configuration file, so I added it to the VB6 directory and read it from the configurations.

However, then I compiled the EXE file from the project and ran it on the same computer that the IDE runs on. I associated the EXE with the configuration file in the same way as in debugging with VB6.EXE, but when the application makes the first method call in one of the .NET classes, it throws an error at runtime, Automation Error. "

In my declarations, I create the following objects from .NET classes, which seem to work fine.

Private objSession As New Session Private curFolder As Folder Private colFolderTemplates As New FolderTemplateCollection Private objLicense As New License 

However, an automation error appears at runtime when the first line is executed:

 Call objSession.Configuration.Configure(connectionString) 

I tried adding the .NET DLLs to the same directory as the Release EXE and re-registering the tlb files, but that did not help. Any suggestions on what I can check?

+4
source share
1 answer

Ok, shot in the dark. What you need to try:

The explicitly new Session object (as well as the License and FolderTemplateCollection):

 Private objSession as Session Set objSession = new Session 

An automation error indicates that the GUIDs from the .NET assembly are not saved. To do this, do this in your C # code - this ensures that all interfaces / classes / virtual tables are preserved, regardless of how many times you compile your C # code:

 [Guid("9AC71CA7-6F82-44A3-9ABE-75354B514A46")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IManager { [DispId(1)] void Display(ADODB.Recordset recordSet); [DispId(2)] void Close(); [DispId(3)] string UserName { get; set; } [DispId(4)] string Password { get; set; } [DispId(5)] string Database { get; set; } [DispId(6)] string Server { get; set; } [DispId(7)] ICriteria Criteria { get; set; } } [Guid("B9BB5B84-8FBD-4095-B846-EC072163ECD3")] [ClassInterface(ClassInterfaceType.None)] [ProgId("MyApp.Manager")] public class Manager : IManager { void Display(ADODB.Recordset recordSet) { } ... } 
0
source

Source: https://habr.com/ru/post/1334677/


All Articles