I am currently working on an app in VB6 that uses COM Interop libraries written in C# using the .NET 2.0 framework.
I used regasm.exe to register the tlb files from the .NET dlls using the /codebase switch. I was then able to successfully build and run the application in the VB6 IDE with no issues. The .NET code uses a config file, so I added it to the VB6 directory and it read from the configurations fine.
However, I then compiled an EXE file from the project an ran it on the same machine as the IDE is running on. I coupled the EXE with the config file just as I had done in debugging with the VB6.EXE, but when the app executes the first call to a method in one of the .NET classes, it throws a run-time error indicating an "Automation Error".
In my Declarations, I instantiate the following objects from the .NET classes, which seems to work fine.
Private objSession As New Session
Private curFolder As Folder
Private colFolderTemplates As New FolderTemplateCollection
Private objLicense As New License
However, the Automation Error comes up at runtime when the first line is executed:
Call objSession.Configuration.Configure(connecti开发者_如何学GoonString)
I tried adding the .NET dlls to the same directory as the Release EXE and re-registering the tlb files, but it did not help. Any suggestions on what I could check?
Ok, shot in the dark. Things to try:
Explicitly new up the Session object (as well as License and FolderTemplateCollection):
Private objSession as Session
Set objSession = new Session
Automation error indicates that the GUIDs from the .NET assembly are not persisting. To do so, do this in your C# code - this then guarantees that all Interfaces/Classes/Virtual tables persist, no matter 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)
{
}
...
}
精彩评论