BinaryFormatter的找不到“大会”在反序列化在C# [英] BinaryFormatter can't find 'Assembly' upon deserialize in c#

查看:638
本文介绍了BinaryFormatter的找不到“大会”在反序列化在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,序列化和反序列化的呼叫,而当我尝试我的DLL附加到另一个程序,它说:找不到程序集​​ASCOM.BHOProxy.Connector,版本= 1.0.0.0 ,文化=中性公钥= 74643865492aa2e6'。

我还可以理解,如果这是一个参考的问题什么的,但问题是,code抛出异常是的 ASCOM.BHOProxy.Connector 。我想到了用某种形式的第三方串行去,但我不是很确定用什么。该组件由通过所述应用程序加载的另一个DLL加载

的序列化的数据被跨越一个TCP连接到一个相同的连接器(通常由另一程序加载相同的文件),在那里它被反序列化传输。当它试图反序列化的异常被抛出,但它只做它时,这是从外部程序调用。在Visual Studio中进行调试时,它工作正常。

 他们的计划 - (后期绑定) - >我的主要DLL  - (.NET项目引用) - >我的连接器的DLL
 

堆栈跟踪:

 在System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   在System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo集信息,字符串名称)
   在System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(字符串对象名,字符串[] memberNames,BinaryTypeEnum [] binaryTypeEnumA,对象[] typeInformationA,的Int32 [] memberAssemIds,ObjectReader objectReader,的Int32 OBJECTID,BinaryAssemblyInfo集信息,SizedArray assemIdToAssemblyTable )
   在System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped记录)
   在System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   在System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.Run()
   在System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler处理器,__BinaryParser serParser,布尔FCHECK,布尔isCrossAppDomain,IMet​​hodCallMessage methodCallMessage)
   在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流serializationStream,HeaderHandler处理器,布尔FCHECK,布尔isCrossAppDomain,IMet​​hodCallMessage methodCallMessage)
   在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流serializationStream)
   在Connector.PortComProxy.De codeMessage派生(List`1 BUFF)在C:\ Users \用户阿伦\文档\的Visual Studio 2012 \项目\ DriverProxy \ PortComClient \ PortComProxy.cs:行259
 

解决方案

我不能说为什么组件未有时发现。不过,我已经使用了 AppDomain.AssemblyResolve 事件负载组件可能无法通过.NET提供正常的程序集加载分辨率发现。就我而言,那是因为我必须找到从注册表项中的组件,使用事件我能够找到并加载程序集preventing大会未发现异常。

最起码攻到这一事件可能让你验证,什么类型的BinaryFormatter的是试图解决。

I have a program that serializes and deserializes calls, and when I try to attach my DLL to another program, it says: Unable to find assembly 'ASCOM.BHOProxy.Connector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=74643865492aa2e6'.

I could understand if this was a reference problem or something, but the problem is that the code that throws the exception is in ASCOM.BHOProxy.Connector. I've thought of going with some kind of third party Serializer, but I'm not quite sure what to use. The assembly is loaded by another DLL which is loaded by the application.

The serialized data gets transmitted across a TCP connection to an identical connector (often the same file loaded by another program), where it is deserialized. The exception is thrown when it tries to deserialize it, but it only does it when this is called from an external program. It works fine when debugging in visual studio.

Their Program --(late binding)--> My Main DLL --(.NET Project Reference)--> My Connector DLL

Stacktrace:

   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at Connector.PortComProxy.DecodeMessage(List`1 buff) in c:\Users\Arlen\Documents\Visual Studio 2012\Projects\DriverProxy\PortComClient\PortComProxy.cs:line 259

解决方案

I can't say why the assembly isn't found sometimes. However I've used the AppDomain.AssemblyResolve event to load assemblies that couldn't be found via the normal assembly load resolution provided by .NET. In my case it was because I had to find the assembly from a registry entry, using the event I was able to find and load the assembly preventing the Assembly not found exception.

At the very least tapping into this event might allow you to verify what type the BinaryFormatter is trying to resolve.

这篇关于BinaryFormatter的找不到“大会”在反序列化在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆