How to use JSON.NET correctly when deseralizing from embedded DLL?

痞子三分冷 提交于 2019-12-12 10:03:29

问题


I'm writing C# code in Visual Studio. I add the embedded DLL inside the project, I am dynamically loading the assemblies. We use JSON.NET to serialize and deserialize objects with type Context.JobDataObj, which is defined in one of the embedded DLLs, and passing the DLLs between various programs.

Unfortunately, whenever I attempt to deserialize, I get the following error:

Type specified in JSON 'Context.JobDataObj, HPMContext, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with 'Context.JobDataObj, HPMContext, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I'm looked up the error in the source code of JSON.NET, the error refers to IsAssignableFrom returning false... When I move the DLL out of the project, the seralization and deseralization works like a charm.

UPDATED:

I've managed to pull in JSON.NET source code and debug it... apparently the only difference between whether it's using the embedded DLL and not is the return value of IsAssignableFrom in the line:

if (objectType != null && !objectType.IsAssignableFrom(specifiedType))

objectType is equal in every way to specifiedType, I've checked all its assemblies, types, interfaces, members, etc etc. Does anyone know how IsAssignableFrom determines it's values?

来源:https://stackoverflow.com/questions/5934160/how-to-use-json-net-correctly-when-deseralizing-from-embedded-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!