我有一个序列化和反序列化调用的程序,当我试图将DLL附加到另一个程序时,它会说:Unable to find assembly 'ASCOM.BHOProxy.Connector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=74643865492aa2e6'.。
我可以理解这是否是一个引用问题,但问题是抛出异常的代码在ASCOM.BHOProxy.Connector中。我考虑过使用某种第三方序列化程序,但我不太清楚该使用什么。程序集由应用程序加载的另一个DLL加载。
序列化的数据通过TCP连接传输到相同的连接器(通常是由另一个程序加载的相同文件),在那里它被反序列化。异常在试图反序列化异常时抛出,但只有在从外部程序调用异常时才会引发异常。在visual studio中调试时,它可以正常工作。
Their Program --(late binding)--> My Main DLL --(.NET Project Reference)--> My Connector DLL堆栈跟踪:
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发布于 2013-01-05 01:03:04
我说不出为什么有时找不到装配。然而,我使用AppDomain.AssemblyResolve事件来加载无法通过.NET提供的常规程序集加载解析找到的程序集。在我的示例中,这是因为我必须从注册表项中找到程序集,使用能够找到并加载程序集的事件防止程序集找到异常。
至少,使用此事件可以让您验证BinaryFormatter试图解决的类型。
发布于 2013-01-06 00:23:46
非常感谢肯,你做到了。这是我对其他可能需要它的人所做的。我不知道它是否有任何区别,无论解析器是否是静态的。
using System.Reflection;
...
public class MyClass{
public MyClass()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
}
private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
{
return typeof(MyClass).Assembly;
}
}https://stackoverflow.com/questions/13821198
复制相似问题