HighTechTalks DotNet Forums  

Interop from a timer event

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Interop from a timer event in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Chris Yager
 
Posts: n/a

Default Interop from a timer event - 08-11-2007 , 02:52 PM






I have a service that accesses a VB6 COM component on a timer event. On
64-bit windows (running in 32-bit "mode") the process fails if it is run in
a secondary thread but works fine when run on the main thread. This
behavior cannot be re-produced in 32-bit environment.

Any help would be greatly appreciated.

The error is:

System.InvalidCastException: Unable to cast COM object of type 'blah.type'
to interface type 'blah.interfacetype'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{[guid....]]}' failed due to the following error: Error loading type
library/DLL. (Exception frm HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

The exact code from the same components runs fine in 64-bit environment
(again running in 32-bit mode) if it is not run on a secondary thread.

I'm not using a primary interop assembly and nothing is running from the GAC
except framework stuff.

thanks,
-chris



Reply With Quote
  #2  
Old   
Chris Yager
 
Posts: n/a

Default Re: Interop from a timer event - 08-11-2007 , 02:59 PM






I should mention: All code is C# targeting x86 cpu using framework 2.0

i have a "fairly" simple example that demonstrates the problem.

-chris

"Chris Yager" <chris.yager (AT) gldsolutions (DOT) com.invalid> wrote

Quote:
I have a service that accesses a VB6 COM component on a timer event. On
64-bit windows (running in 32-bit "mode") the process fails if it is run in
a secondary thread but works fine when run on the main thread. This
behavior cannot be re-produced in 32-bit environment.

Any help would be greatly appreciated.

The error is:

System.InvalidCastException: Unable to cast COM object of type 'blah.type'
to interface type 'blah.interfacetype'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{[guid....]]}' failed due to the following error: Error loading type
library/DLL. (Exception frm HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

The exact code from the same components runs fine in 64-bit environment
(again running in 32-bit mode) if it is not run on a secondary thread.

I'm not using a primary interop assembly and nothing is running from the
GAC except framework stuff.

thanks,
-chris




Reply With Quote
  #3  
Old   
Chris Yager
 
Posts: n/a

Default Re: Interop from a timer event - 08-12-2007 , 07:35 PM



I'd considered that but it behaves well in 32-bit windows.

thanks for the response,
-chris

"Mattias Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote

Quote:
I have a service that accesses a VB6 COM component on a timer event. On
64-bit windows (running in 32-bit "mode") the process fails if it is run
in
a secondary thread but works fine when run on the main thread. This
behavior cannot be re-produced in 32-bit environment.

Any help would be greatly appreciated.


I'm guessing the thread has the wrong ApartmentState.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



Reply With Quote
  #4  
Old   
Johannes Passing
 
Posts: n/a

Default Re: Interop from a timer event - 08-13-2007 , 11:47 AM



Hi Chris,

the error message indicates that the typelib cannot be loaded - can you
load it manually using LoadRegTypeLib (on 64-bit windows) or do you get
the same error?

--Johannes

Chris Yager wrote:
Quote:
I'd considered that but it behaves well in 32-bit windows.

thanks for the response,
-chris

"Mattias Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote in message
news:e4p2A8S3HHA.1184 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
I have a service that accesses a VB6 COM component on a timer event. On
64-bit windows (running in 32-bit "mode") the process fails if it is run
in
a secondary thread but works fine when run on the main thread. This
behavior cannot be re-produced in 32-bit environment.

Any help would be greatly appreciated.

I'm guessing the thread has the wrong ApartmentState.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



--
Johannes Passing - http://int3.de/


Reply With Quote
  #5  
Old   
Chris Yager
 
Posts: n/a

Default Re: Interop from a timer event - 08-15-2007 , 09:40 AM



Thanks to all for the help.
The problem was the apartment state.

I spawned an additional thread off the timer's thread and set the apartment
state to "STA" and everything works as expected.

Thanks again,
-chris

"Mattias Sjögren" <mattias.dont.want.spam (AT) mvps (DOT) org> wrote

Quote:
I have a service that accesses a VB6 COM component on a timer event. On
64-bit windows (running in 32-bit "mode") the process fails if it is run
in
a secondary thread but works fine when run on the main thread. This
behavior cannot be re-produced in 32-bit environment.

Any help would be greatly appreciated.


I'm guessing the thread has the wrong ApartmentState.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.