Invalid Cast exception on COM interop in Windows Service
- From: pmgreen <pmgreen.216oxy@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 Jan 2006 23:36:12 +0100
I've got a peice of code that creates a COM object and attempts to use
it. It works fine when it is run as an application. However, it
throws an "invalid cast" exception when it is run in a Windows Service.
The code snippet:
Dim strClass As String = "PSIGPoller.CWorkManager"
Dim obj As Object
obj =
Activator.CreateInstance(Type.GetTypeFromProgID(strClass))
m_objWorkManager = CType(obj, CWorkManager) '<-- throws
'invalid cast' in service
A few more notes:
- When it runs as an application, it is using exactly the same interop
DLLs as the service is using. The app and the service .exe files are
in the same directory.
- The service works when it is run on the machine with the development
platform. If it is installed on a machine without the development
platform we get the exception. I currently have 2 development machines
that the service will run correctly on, and 2 test machines that it will
not run on.
- The .Net framework version on both machines is reported as
1.1.4322.573.
While googling around I've read several posts on the net about various
reasons that you can get an invalid cast, ranging from threading model
differences between the app/service and the DLL's to security issues
with the DLL. If this was an app/service difference it would seem more
straight forward; however, when the service runs correctly on the
development machines, it confuses things a bit. If there was a
threading model issue, why would the service run correctly on any
machine? If there was a problem with security access to the COM
object, why would the application run correctly - the service is
logging in using the same user account that I run the application
under.
This looks like it boils down the either something that is installed
with the SDK or VS7 development environment, or something that happens
when the service is built.
I'm copying everything from the bin directory when I grab the files to
install the it on the other machine. Is there any other DLL's that I
would need beyond what is in the bin directory? (The fact that the
application works makes this point more interesting...)
Any ideas would be appreciated.
Thanks,
Perry
--
pmgreen
------------------------------------------------------------------------
pmgreen's Profile: http://www.hightechtalks.com/m663
View this thread: http://www.hightechtalks.com/t2324212
.
- Follow-Ups:
- Prev by Date: Re: tlbexp in 2.0 requires ComVisible?
- Next by Date: Kernel32 exception when rendering UserControl in IE
- Previous by thread: Re: tlbexp in 2.0 requires ComVisible?
- Next by thread: Re: Invalid Cast exception on COM interop in Windows Service
- Index(es):
Relevant Pages
|