Casting exception is not easily explained by the problem with the standard program directory. What about everything that should be different when you launch the application from the VB6 IDE, and not directly.
You will need to use a debugger to find out what is going wrong. Fortunately, this is easy when you use VB6. Start by opening your .NET project in Visual Studio. Project + Properties, Debug tab. Select "Run external program", click the dots button and go to vb6.exe. It should be located in the c: \ program files \ microsoft visual studio \ vb98 \ vb6.exe folder if you used the default installation options.
You can set the "Command Line Parameters" path to your .vbp project so that the IDE automatically downloads it. Not necessary.
Debugging + Exceptions, check the box "Exclude common runtime language". Press F5 to start the debugger. Now the VB6 IDE will open, if necessary, download the VB6 project. Run the project and recreate the failure case. This should trigger a breakpoint in the Visual Studio debugger. You may need to switch to it manually, the taskbar button should blink. Use normal debugging tools to find out why an exception was thrown.
Note that you can also set breakpoints in Visual Studio, useful if you need to execute one-step code to find out what happened. When you press F5, the breakpoint indicator becomes hollow because the DLL is not yet loaded. Once your VB6 project creates a class object from your .NET code, the DLL will load (visible in the output window) and the breakpoint indicator will become solid. If this does not happen, you may need to run Regasm.exe with the / codebase parameter so that the DLL in the bin \ Debug folder of the project is registered as a COM server.
source share