This repo demonstrates a possible bug on Windows 7. It occurs when a .NET user control's event is handled by VB6 code, and that VB6 code instantiates a .NET class exposed to COM for the very first time in the program.
- We only get the issue in Windows 7 SP1 after updates have been installed. This works fine on Windows 10 and on a clean install of Windows 7 SP1. However, after running windows updates, we start getting the error in Windows 7.
- The error does not occur in development. Registering the .NET dll with regasm makes it always work. VB6 only uses registered dlls as references so you cannot reproduce it in development (unless there is some magic you can do for reg-free assembly loading in the VB6 IDE that I don't know about.)
- Instantiating the class before the event makes it work. The error only occurs if the class instantiated in the VB6 handler is created for the first time.
- Start the application.
- Create the form with the .NET user control
- Click the button to raise the event
- VB6 code creates a new
MyTestClass
- At this point it will show a message box with "test" if it works, or an automation error if it fails.
- Open
DotNetControls.csproj
in VS 2017+ with Administrator privileges (for COM registration) and build. The post-build commands copy the files and manifests to thebuild
folder in the root of the project. - Open the InteropTest.vbp project Make the exe, putting it in the
build
folder. - Copy all 4 build files to various machines for testing. Don't use the dev machine without unregistering the COM-exposed dll first. It works on everything but Windows 7 SP1 with updates for me.