Hi All,
I am getting a System.Runtime.Serialization.SerializationException and have no idea how to fix it. I get this error at the time deserializing the object.
I am developing a VSPackage in C#. From the Initialize() method of my package class (which is derived from class Package), I am trying to read/write a serialized class.
I can see in the forum that few other people have had these problems but I could not find any answer.
Could anybody please give me some pointers on how to fix this problem I have used Serialization before but it seems a lot more complicated with Visual Studio 2005. The MSDN help does not help me much.
Any help would be highly appreciated.
Thanks a lot.
===========================================
private MySettings ReadSettings()
{
"MyCompany");String AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
AppDataPath = Path.Combine(AppDataPath,
AppDataPath = Path.Combine(AppDataPath,
"MyApplication");AppDataPath = Path.Combine(AppDataPath,
"MySettingsFile.dat"); /* AppDataPath is like C:\Documents and Settings\currentuser\Application Data\MyCompany\MyApplication\MySettingsFile.dat*/
MySettings settings =null;
if (!File.Exists(AppDataPath))
{
settings = new MySettings(); // The default settings
WrirteSettings(settings );
return settings;
}
FileStream stream = (FileStream)File.Open(AppDataPath, FileMode.Open);
if (stream != null)
{
BinaryFormatter formatter = new BinaryFormatter();
if (formatter != null)
{
// This is where I get the error.
settings = (CMSSettings)formatter.Deserialize(stream);
}
stream.Close();
}
return settings;
}
private MySettings WriteSettings(MySettings settings)
{
String AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
AppDataPath = Path.Combine(AppDataPath, "MyCompany");
AppDataPath = Path.Combine(AppDataPath, "MyApplication");
String MyAppFolder = AppDataPath;
AppDataPath = Path.Combine(AppDataPath, "MySettingsFile.dat");
Directory.CreateDirectory(MyAppFolder);
FileStream stream = (FileStream)CMSUtil.CreateFile(AppDataPath);
if (stream != null)
{
BinaryFormatter formatter = new BinaryFormatter();
if (formatter != null)
{
formatter.Serialize(stream, settings);
}
stream.Close();
}
}
// Define MySettings Class
[Serializable()]public class MySettings
{
public bool bSettingsField1;
public MySettings()
{
bSettingsField1 = true;
}
}
This is how the error looks like:
VSIP: Developer edition, all third-party packages allowed to load.
Exception occurred System.Runtime.Serialization.SerializationException: Unable to find assembly 'CMSVSStudio, Version=1.0.2224.23450, Culture=neutral, PublicKeyToken=2c858df1ab695077'.
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)
==============================================

Clueless SerializationException!
blomm
If you are supplying the full path to an assembly, meaning that the path is something like C:\Documents and settings\username\My Documents\Visual Studio 2005\projects\..., then what is happening is we are loading the assembly using something similar to the Assembly.LoadFrom method. There are some issues with this method when trying to locate referenced assemblies, and there are plenty of comments about LoadFrom on Suzanne Cook's blog at http://blogs.msdn.com/suzcook/default.aspx.
You are going to need to either move your assemblies around, such as put them into the GAC, in the same directory as Visual Studio, or in one of the paths listed in the Probing section of devenv.exe.config.
Craig