473,419 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

SoapFormatter.Deserialise cannot read a Font object?

I was trying to use Soap serialisation to save some systems settings
how ever it fails if the settings contain a Font object, works fine if
the Font object is not in the object being serialised.

Font is marked [Serializable()] in the MS documentation.

Exception has been thrown by the target of an invocation.

at System.Reflection.RuntimeConstructorInfo.Serializa tionInvoke(Object
target, SerializationInfo info, StreamingContext context)
at
System.Runtime.Serialization.ObjectManager.Complet eISerializableObject(Object
obj, SerializationInfo info, StreamingContext context)
at
System.Runtime.Serialization.ObjectManager.FixupSp ecialObject(ObjectHolder
holder)\r\n at System.Runtime.Serialization.ObjectManager.DoFixup s()
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.Deserialize(HeaderHandler handler, ISerParser serParser)
at
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter.Deserialize(Stream
serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter.Deserialize(Stream
serializationStream)
at MiTekAUS.mi2020mn.JigViewSettings.Load() in
c:\\mi2020mn\\mi2020mn\\jigviewsettings.cs:line 133

Nov 12 '05 #1
1 2270

Use a surrogate to Serialize and Deserialize the Font class yourself.

public class SoapFormatterEx : IFormatter
{
private SoapFormatter _formatter;

public SoapFormatterEx()
{
// 1. Create an instance of a Soap Formatter.
_formatter = new SoapFormatter();

// 2. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();

// 3. Construct an instance of our serialization surrogate type
FontSurrogate vss = new FontSurrogate();

// 4. Tell the surrogate selector to use our object when a
// Font object is serialized/deserialized.
ss.AddSurrogate(typeof(System.Drawing.Font),
new StreamingContext(StreamingContextStates.All), vss);

// 5. Have the formatter use our surrogate selector
_formatter.SurrogateSelector = ss;
}

#region IFormatter Members

public void Serialize(System.IO.Stream serializationStream, object
graph)
{
_formatter.Serialize(serializationStream,graph);
}

public SerializationBinder Binder
{
get { return _formatter.Binder; }
set { _formatter.Binder = value; }
}

public StreamingContext Context
{
get { return _formatter.Context; }
set { _formatter.Context = value; }
}

public ISurrogateSelector SurrogateSelector
{
get { return _formatter.SurrogateSelector; }
set { _formatter.SurrogateSelector = value; }
}

public object Deserialize(System.IO.Stream serializationStream)
{
return _formatter.Deserialize(serializationStream);
}

#endregion

#region FontSurrogate class

private class FontSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info,
StreamingContext context)
{
Font font = obj as Font;
FontConverter fc = new FontConverter();
info.AddValue("Encoded",fc.ConvertToString(font));
}

public object SetObjectData(object obj, SerializationInfo info,
StreamingContext context, ISurrogateSelector selector)
{
FontConverter fc = new FontConverter();
return fc.ConvertFromString(info.GetString("Encoded"));
}
}

#endregion
}

--
mridey
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1068267.html

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Philip Reed | last post by:
I'm trying to write a preferences-handling infrastructure that serializes prefs to XML. Basically I want to read in a common "default" prefs set, then read in the user's prefs and override the...
2
by: Jarda | last post by:
Hi all, i'm looking for some performance comparison some charts. I have read the xmlserializer is better, more flexible and faster (analyzing data types in constructor), but there are some...
2
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
0
by: GrandpaB | last post by:
I have an error that I have not been able to find. Any insight you can offer would be most appreciated. I believe that the problem is associated with the SoapFormatter. The application allows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.