npython.exe是运行python脚本(使用Python.net导入.net dll)的唯一选项吗?

时间:2018-10-06 11:34:39

标签: c# python .net serialization python.net

我的代码库主要位于.net框架中。我正在尝试通过python.net在python脚本中提供其中一个库。我可以通过

使其成功运行
  1. 下载python.net源代码,然后从源代码构建npython.exe / python.runtime.dll
  2. 像这样npython.exe MyPythonScript.py
  3. 运行python脚本

一切正常。

但是,如果不使用我的npython版本,而是使用pip在我的anaconda python中直接安装pythonnet软件包,然后尝试运行类似C:\Anaconda3\python MyPythonScript.py的脚本,则会出现类似

的错误
The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[RefData.LookUpDataItem, RefData, Version=1.0.6841.27933, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.
   at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns)
   at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns)
   at System.Runtime.Serialization.NetDataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at Microsoft.ApplicationServer.Caching.Utility.Deserialize(Byte[][] buffers, Boolean checkTypeToLoad, Object context, IEnumerable`1 knownTypes)
   at Microsoft.ApplicationServer.Caching.RoutingClient.SendMsgAndWait(RequestBody reqMsg, IRequestTracker& tracker)
   at Microsoft.ApplicationServer.Caching.DataCache.SendReceive(RequestBody reqMsg, IMonitoringListener listener)
   at Microsoft.ApplicationServer.Caching.DataCache.InternalGet(String key, DataCacheItemVersion& version, String region, IMonitoringListener listener)
   at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass49.<Get>b__48()

程序从Microsoft AppFabric缓存服务器检索一些数据。缓存dll位于同一位置。我的库dll或使用它们的python脚本没有任何变化。只是不同的调用。

在Ananconda python 3.6安装和独立python 2.7安装中都观察到相同的行为。这是完全不可能的吗?还是导致问题的缓存和序列化特有的东西?在这里的任何帮助将不胜感激。

0 个答案:

没有答案