Derek
Thu Jul 03 12:36:30 CDT 2003
Yes it does derive from ISerializable. Full class listing is:
using Microsoft.Win32;
using System;
using System.Runtime.Serialization;
namespace Salamander.Addins.CodeStore.Engine
{
/// <summary>
/// Summary description for Options.
/// </summary>
[Serializable]
internal class Options: ISerializable
{
#region Class Data
internal string ServerUrl =
"
http://www.salamandersoftware.biz/codestore/";
internal string LocalPath = String.Empty;
#region Proxy Settings
internal bool UseProxy = false;
internal bool BypassProxyOnLocal = false;
internal bool ProxyAuthorisation = false;
internal string ProxyAddress = String.Empty;
internal int ProxyPort = 0;
internal string ProxyUser = String.Empty;
internal string ProxyPassword = String.Empty;
#endregion
#endregion
#region Constructors
/// <summary>
/// Default Constructor.
/// </summary>
internal Options() {}
/// <summary>
/// Construct an Options object from serialization.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected Options(SerializationInfo info, StreamingContext context)
{
int version = info.GetInt32("_OptVersion");
this.ServerUrl = info.GetString("ServerUrl");
this.LocalPath = info.GetString("LocalPath");
this.UseProxy = info.GetBoolean("UseProxy");
this.BypassProxyOnLocal = info.GetBoolean("BypassProxyOnLocal");
this.ProxyAuthorisation = info.GetBoolean("ProxyAuthorisation");
this.ProxyAddress = info.GetString("ProxyAddress");
this.ProxyPort = info.GetInt32("ProxyPort");
if (version >= 2)
{
//TODO: Add encryption support to version 2.
}
else
{
// Clear text used in version 1.
this.ProxyUser = info.GetString("ProxyUser");
this.ProxyPassword = info.GetString("ProxyPassword");
}
}
#endregion
/// <summary>
/// Populates a SerializationInfo with the data needed to serialize the
target object.
/// </summary>
/// <param name="info">The SerializationInfo to populate with
data.</param>
/// <param name="context">The destination for this serialization.</param>
public virtual void GetObjectData(SerializationInfo info, StreamingContext
context)
{
info.AddValue("_OptVersion", 1);
info.AddValue("ServerUrl", this.ServerUrl);
info.AddValue("LocalPath", this.LocalPath);
info.AddValue("UseProxy", this.UseProxy);
info.AddValue("BypassProxyOnLocal", this.BypassProxyOnLocal);
info.AddValue("ProxyAuthorisation", this.ProxyAuthorisation);
info.AddValue("ProxyAddress", this.ProxyAddress);
info.AddValue("ProxyPort", this.ProxyPort);
//TODO: Add encryption to version 2.
info.AddValue("ProxyUser", this.ProxyUser);
info.AddValue("ProxyPassword", this.ProxyPassword);
}
}
}
"Dave" <kdlevine@wi.rr.com> wrote in message
news:eVvFt8XQDHA.1752@TK2MSFTNGP12.phx.gbl...
> This may be too simplistic, but did you derive your class from
> ISerializable? You need to both mark it as Serializable and also as
derived
> from ISerializable
>
>
> "Derek Lakin" <derek_lakin@lineone.net> wrote in message
> news:%23HyV8DXQDHA.2212@TK2MSFTNGP12.phx.gbl...
> > Thanks for the idea, but unfortunately I still have the same problem.
Any
> > other ideas?
> >
> > Derek.
> >
> > "James X. Li" <donotreplay@abc.net> wrote in message
> > news:%239kfA7WQDHA.3880@tk2msftngp13.phx.gbl...
> > > Try to add the following line into to your add-in assembly:
> > >
> > > [assembly:AllowPartiallyTrustedCallers]
> > >
> > >
> > >
> > > James X. Li
> > >
> > > "news.microsoft.com" <derek_lakin@lineone.net> wrote in message
> > > news:eAec2dWQDHA.2424@tk2msftngp13.phx.gbl...
> > > > I have created an add-in for VS.NET and when it starts I want the
> add-in
> > > to
> > > > read the options from file.
> > > > I have created a class (with the [Serializable] attribute set) that
> > > contains
> > > > the options and implemented GetObjectData(SerializationInfo info,
> > > > StreamingContext context) as well as a copy constructor: protected
> > > > Options(SerializationInfo info, StreamingContext context).
> > > >
> > > > The serialization process definately works. However, on startup I
try
> to
> > > > create an instance of my Options class and deserialize the file, but
I
> > get
> > > a
> > > > SerializationException as follows:
> > > >
> > > > Engine.LoadOptions:
> System.Runtime.Serialization.SerializationException:
> > > > Cannot find the assembly CodeStore, Version=2.0.0.0,
Culture=neutral,
> > > > PublicKeyToken=null.
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembl
> > > > y()
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAs
> > > > semblyInfo 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.ObjectMap.Create(String
> > > name,
> > > > String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[]
> > > > typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader,
> > Int32
> > > > objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
> > > > assemIdToAssemblyTable)
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWith
> > > > MapTyped(BinaryObjectWithMapTyped record)
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWith
> > > > MapTyped(BinaryHeaderEnum binaryHeaderEnum)
> > > > at
> > System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(Head
> > > > erHandler handler, __BinaryParser serParser, Boolean fCheck,
> > > > IMethodCallMessage methodCallMessage)
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
> > > > tream serializationStream, HeaderHandler handler, Boolean fCheck,
> > > > IMethodCallMessage methodCallMessage)
> > > > at
> > > >
> > >
> >
>
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
> > > > tream serializationStream)
> > > > at Salamander.Addins.CodeStore.Engine.Engine.LoadOptions() in
> > > > c:\development\codestore\engine\engine.cs:line 78
> > > >
> > > > Why can't it find the assembly? It is not calling out to a separate
> > > library,
> > > > it's a single dll for the add-in and that's where the code is being
> > called
> > > > from. The file it is trying to read is inthe same location as the
dll,
> > > too.
> > > >
> > > > The LoadOptions function looks like this:
> > > >
> > > > internal void LoadOptions()
> > > > {
> > > > try
> > > > {
> > > > string path = GetAddInPath() + this.optionsFileName;
> > > > Stream stream = new FileStream(path + ".options", FileMode.Open,
> > > > FileAccess.Read, FileShare.Read);
> > > > try
> > > > {
> > > > IFormatter formatter = new BinaryFormatter();
> > > > this.options = (Options)formatter.Deserialize(stream); // <--
> This
> > is
> > > > line 78 where the exception is raised.
> > > > }
> > > > catch (System.Exception exc)
> > > > {
> > > > System.Diagnostics.Trace.WriteLine(exc.ToString(),
> > > > "Engine.LoadOptions");
> > > > }
> > > > finally
> > > > {
> > > > stream.Close();
> > > > }
> > > > }
> > > > catch (System.Exception exc)
> > > > {
> > > > if (exc is FileNotFoundException)
> > > > {
> > > > // No options file, so write the current default options to
file.
> > > > SaveOptions();
> > > > }
> > > > else
> > > > {
> > > > System.Diagnostics.Trace.WriteLine(exc.Message,
> > > "Engine.LoadOptions");
> > > > }
> > > > }
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>