问题
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