04-06-2011 01:05 AM - edited 04-06-2011 01:12 AM
04-07-2011 11:06 AM
This is really an issue with how the .NET framework works. Assemblies loaded by file path using LoadFrom, which is what the .NET adapter does, are loaded in a different context then assemblies that aren't loaded by file path (not sure why Microsoft did this, maybe security reasons). This generally isn't a problem unless you are serializing and deserializing such types or trying to marshal them between appdomains. In your use case, from the error message, it sounds like you are deserializing such types. You can workaround the issue by creating an AssemblyResolve event handler to refer back to the already loaded assembly when .NET tries to load it in the Load context. Your problem is very similar to the one in the following forum post which has more details on how to do this:
http://forums.ni.com/t5/NI-TestStand/Loading-app-config-stuff-from-net-assembly/td-p/1052769
Hope this helps,
-Doug
04-07-2011 11:10 AM - edited 04-07-2011 11:12 AM
In reading your post more carefully. It might not be exactly what I was thinking, though it might be worth giving the AssemblyResolve fix a try anyway. How exactly is the WPF host loading the assembly?
-Doug
04-08-2011 02:02 AM
The WPF host is statically linked to the TsDllCall.dll and it uses 'new' operator to create the object. For the function call in the sequence file, it uses XmlSerializer to create the object. It gives no error if I use the 'new' operator to create the object.
I have created the event handler for AssemblyResolve. It requested the following assembly:
TsDllCall.XmlSerializers
TsDllCall.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
I have genarated the TsDllcall.XmlSerializers.dll using SGen and put it together with the 2 TsDllCall.dll. I load the one used by the sequence file in the event handler but I still get the same error. I'm not sure if I'm doing it correctly.
However, I have found another solution: http://sixlettervariable.blogspot.com/2007/05/net-xmlserializer-and.html
Place this in my app.config and the problem has gone.
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>
I don't know what is it doing exactly. I will use this solution for now.
Thanks for the help.