Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

InvalidCastException using a 2nd AppDomain

$
0
0

Hi all,

we are loading an instance of a class from a 3rd party assembly in a 2nd AppDomain. It contains a control which we host on a Form. Certain events are sent back into our assemblies for processing. Some of our DLLs also get laoded into the 2nd AppDomain.

When an event is processed from the 2nd AppDomain we are getting an InvalidCastException when we are trying to cast between 2 of our own classes from our own assemblies.

Unable to cast object of type 'xxxxxxx' to type 'xxxxxx'.

I've spent a bit of time searching for an answer. I've seen similar posts in these forums and others. Based on these posts, I've tried all of the following without any success.

1. We are using LoadFrom() to load the assembly. I've read that the same types from the same DLL aren't the same if they are loaded in different contexts. So I changed it to use Load()  using the assembly's strong name but that made no difference.

2. I've used Process Explorer to make sure that both AppDomains are loading the same DLL's from the same location. ie. our DLLs that contain the class defintions.

3. I've used Fusion Log Viewer to check if there are any loading issues but its not showing any problems.

4. Tried handling the AssemblyResolver. Although I don't see how this helps as my assemblies are being found.

Any other suggestions on what may be the problem ?

Thanks,
Anthony.


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>