I'm trying to debug some code that uses reflection to load plugins
Here's the debugging code:
Type a = methodInfo.GetParameters()[0]
.ParameterType.BaseType;
Type b = typeof(MessageContext);
Debug.WriteLine(a.AssemblyQualifiedName);
Debug.WriteLine(b.AssemblyQualifiedName);
Debug.WriteLine(a.Equals(b));
And here is its output:
OrtzIRC.Common.MessageContext, OrtzIRC.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
OrtzIRC.Common.MessageContext, OrtzIRC.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
False
I don't understand what would make these two types different?
Equals() Method is used to check whether the underlying system type of the current Type is the same as the underlying system type of the specified Object or Type.
Objects are not compared by value: two objects are not equal even if they have the same properties and values. This is true of arrays too: even if they have the same values in the same order. Objects are sometimes called reference types to distinguish them from JavaScript's primitive types.
Inequality operator !=returns true if its operands are not equal, false otherwise. For the operands of the built-in types, the expression x != y produces the same result as the expression !( x == y) .
The same class / type loaded by different app domains [.NET] or class loaders [Java] will not compare equal and are not assignable to/from each other directly.
You likely have two copies of the DLL containing that type - one loaded by the main program and one loaded by one of the Assembly.Load*(...)
methods?
Try displaying / comparing the properties:a.Assembly.Equals(b.Assembly)
anda.Assembly.Location.Equals(b.Assembly.Location)
In general, you only want one copy of each DLL and have it loaded into a single app domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With