I have an interesting case which neither I nor my colleagues can understand. We have developed a plugin for a 3rd party software (Autodesk Revit 2018) in .NET C#. Both our plugin and the host application (Revit) uses an assembly called Xceed.AvalonDock.dll, but with different versions. Our plugin uses the version 3.2.0, Revit uses 2.0.0.
On some clients' machine launching our application fails due to the following TypeLoadException:
System.TypeLoadException
GenericArguments[0], 'Xceed.Wpf.AvalonDock.Layout.ILayoutPanelElement', on 'Xceed.Wpf.AvalonDock.Layout.LayoutGroup`1[T]' violates the constraint of type parameter 'T'.
at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.Instantiate(Type[] inst)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
Our project references Xceed like this (copied from our .vcsproj file):
<Reference Include="Xceed.Wpf.AvalonDock, Version=3.2.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Extended.Wpf.Toolkit.3.2.0\lib\net40\Xceed.Wpf.AvalonDock.dll</HintPath>
<Private>True</Private>
</Reference>
Clearly we specify the exact DLL version (and even a public key token). I have tested on my machine and even though Revit loads the 2.0 version of the dll (which it needs), our plugin loads the 3.2 version at startup.
What's puzzling me is that the error message of the exception seems to be wrong. Why? Take a look at the declaration of LayoutGroup<>:
[Serializable]
public abstract class LayoutGroup<T> : LayoutGroupBase ... where T : class, ILayoutElement
The message states that ILayoutPanelElement does not satisfy the where clause. It is a subtype of ILayoutElement and all its subtypes are reference types (even if they were structs, I believe an automatic boxing would take care of that). So apparently it does satisfy the where clause, doesn't it?
What can cause such an exception? Is the message a red herring? Could it be that somehow on the client's computer the DLL version gets mixed up? If so, why doesn't it do on our machine(s). I have tested on both Windows 7 and 10, and cannot reproduce this exception.
If anybody has an idea, please help!
UPDATE: AvalonDock is open-source. I have checked both revisions (version 2.0 and 3.2) for the declaration of LayoutGroup, ILayoutElement, and ILayoutPanelElement and the exception message still seems to be wrong to me. Not much has changed in this part of the code.