Question

I'm trying to use a supplied DLL that load the same dependent DLL from two different locations.

In the supplier deployment the two locations conicide, but not in mine.

When code runs I have a class cast exception:

Unable to cast [A]Type to [B]Type

The error is the same occurred to the op in StackOverflow question Different location of assemblies stoped the type casting.

The two types are the same type loaded from the two different locations of the DLL (the same physical file copied in two directories).

I've tried to use Strong Name with signature of the double DLL, but it did not work.

Is there a way I can tell CLR to treat the two types as the same type?

Was it helpful?

Solution

I'm pretty sure this isn't allowed for a lot of reasons.

First off, let's say you have 2 assemblies. The first defines Animal and has a descendant called Dog. The second defines Animal. Both assemblies use the same namespace.

During runtime what happens when you declare var B = new Dog();? Should the code swap the second assembly's version of Animal in there or not?

What if you declare var A = new Animal();? IMHO, the code should simply implode to prevent it.

From a security perspective you would absolutely not want someone to simply link in another assembly that defines the same namespace as your library to swap out a particular class.

Point is, by linking to both physical assemblies containing the exact same types you are introducing a huge problem that there is no real way to solve. Change your code to work the same way as the supplier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top