Debug an AmbiguousMatchException when calling an AppDomain.CreateInstanceAndUnwrap application in .NET.
I have an application that is throwing an AmbiguousMatchException when I call AppDomain.CreateInstanceAndUnwrap to instantiate another AppDomain. This is happening on a client computer that I don't have direct access to. I think the problem is that there are two copies of the same assembly. Is there a way to figure out if this is the case and where are the two assemblies being loaded? Will the merge log include additional information?
source to share
The merge log might help, but another option might be to bind the event AssemblyLoad
:
AppDomain.CurrentDomain.AssemblyLoad += (s, a) =>
{
Console.WriteLine(a.LoadedAssembly.FullName);
Console.WriteLine(a.LoadedAssembly.CodeBase);
};
There are two main reasons for this error:
- name match - that is, Foo.dll and Bar.dll are of type
Some.Namespace.Type
- different versions (mainly GAC) that are referenced by different components - for example your DALs are loaded by v2 of some DLL, and your UI / utility code is loading v4 of the same DLL
Of course, another option is that yours AppDomain
infected each other (it is very (too?) Easy to accidentally suck a link over a border AppDomain
by exposing it to an API MarshalByRef
object).
source to share