Deserialization exception in AppDomain

耗尽温柔 提交于 2019-12-11 23:16:58

问题


I have a problem with deserialization of an object:

byte[] cardData;

// Serialize
var mySerializer1 = new BinaryFormatter();
using (var ms = new MemoryStream())
{
    mySerializer1.Serialize(ms, new SuperClass());
    cardData = ms.ToArray();
}

// Deserialize
var mySerializer2 = new BinaryFormatter();
using (var ms = new MemoryStream(cardData))
    mySerializer2.Deserialize(ms);   // throws an exception

In the same file:

[Serializable]
public class SuperClass
{ }

Exception:

    System.Runtime.Serialization.SerializationException: Unable to find assembly "SKM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null".
в System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
в System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
в 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)
в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
в System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
в SKM.InputFiles.InputFileMsr.GetRecords() в c:\Stas\Projects\CardMaster\Current\MACS\Application\BankProcessors\SKM\InputFiles\InputFileMsr.cs:строка 204

The SKM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null is the assembly in which I run all this code. Why does CLR cannot find it?

I tested this code in a separate application and it all works fine. But in my application throws an exception. Maybe this is because of AppDomain in which i load this dll? How to fix it?

UPDATE 2: Add Fusion logs.

SKM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:

    *** Assembly Binder Log Entry  (28.05.2015 @ 17:05:51) ***

The operation failed.
Bind result: hr = 0x80070002. Не удается найти указанный файл.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = SKM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

*** Assembly Binder Log Entry  (28.05.2015 @ 17:05:51) ***

The operation failed.
Bind result: hr = 0x80070002. Не удается найти указанный файл.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = SKM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

SKM:

    *** Assembly Binder Log Entry  (28.05.2015 @ 17:05:51) ***

The operation failed.
Bind result: hr = 0x80070002. Не удается найти указанный файл.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = SKM
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SKM | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM.DLL.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM/SKM.DLL.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM.EXE.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM/SKM.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (28.05.2015 @ 17:05:51) ***

The operation failed.
Bind result: hr = 0x80070002. Не удается найти указанный файл.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = SKM
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SKM | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Stas\Projects\CardMaster\Current\MACS\Application\Application.DataProcessing\bin\Debug\Application.DataProcessing.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM.DLL.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM/SKM.DLL.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM.EXE.
LOG: Attempting download of new URL file:///C:/Stas/Projects/CardMaster/Current/MACS/Application/Application.DataProcessing/bin/Debug/SKM/SKM.EXE.
LOG: All probing URLs attempted and failed.

来源:https://stackoverflow.com/questions/30507492/deserialization-exception-in-appdomain

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