Unable to use Interop. Probably being stupid
I am trying to use a 3rd-party Interop assembly called SmartWIM.
I have added it as a reference and added an Import statement
Imports SmartWIMLib
I then initilalise it with
Dim objSmartWim As New SmartWIM
All pretty standard stuff, I've done this countless times with Interops. However, whenever I try and use any methods I get the following error
Unhandled Exception: System.TypeInitializationException: The type initializer for 'VSSImage.Module1' threw an exception. ---> System.Runtime.Inte
ropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {2AA14EBC-F945-44F3-80CA-EE916BE02111} failed due to the following error: 80040154.
at VSSImage.Module1..cctor() in D:\data\willimw\Visual Studio 2010\Projects\VSSImage\VSSImage\Module1.vb:line 7
--- End of inner exception stack trace ---
at VSSImage.Module1.Main()
Re: Unable to use Interop. Probably being stupid
Ah. Now I think I know why. The associated DLL has to be registered on the target machine too. Damn, that's annoying. Now I need to find out how to have my application register a certain DLL whilst the app is running and then unregister it at the end.
Re: Unable to use Interop. Probably being stupid
Yes, the Interop DLL is simply a bridge that allows your app to INTEROPerate with a COM component. That can't happen if there's no COM component to interoperate with.
You use Regsvr32.exe to register and unregister COM components. You can run it using Process.Start, just like any other program. I've never tried doing it on the fly though.
Re: Unable to use Interop. Probably being stupid
Yes, I think that's what I'll have to do. It seems a little clunky but I guess I don't have much choice.