TheSwamp

Code Red => .NET => Topic started by: mohnston on August 24, 2009, 06:37:09 PM

Title: .NET to VB to VBA
Post by: mohnston on August 24, 2009, 06:37:09 PM
I'm getting tangled up in COM/.NET interop.
I'm updating some code for upgrade to 2010 so I'm running into compatability issues.
I've written a component in C#.NET that I use in VBA to allow dragging (jigging) of entities. So far, so good.
The component works fine when I use it from VBA.

Are you still reading? good.
Now I would like to use the same component from VB (a dll. referenced into VBA) and I'm running into problems.

When I try I get this error message:
Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException

Are you still reading? good.
So . . . I've got a VBA project (dvb) with a reference to a VB program (dll) that references a .NET component (dll).
Plus, the VBA project itself ALSO references the same .NET component.

Is this a recipe for disaster? Or should this work and I'm just missing something?
Title: Re: .NET to VB to VBA
Post by: It's Alive! on August 24, 2009, 06:52:54 PM
you might try using [STAThread] in your managed code
Title: Re: .NET to VB to VBA
Post by: mohnston on August 24, 2009, 07:16:00 PM
you might try using [STAThread] in your managed code
said the wise man.

That is exactly what it needed.
Thanks a million.
Title: Re: .NET to VB to VBA
Post by: It's Alive! on August 24, 2009, 07:29:25 PM
Glad it worked  :-)
Title: Re: .NET to VB to VBA
Post by: Kerry on August 24, 2009, 08:38:19 PM

Well done.

I imagine a few people would like a cheat sheet for doing this ( in the near future).