Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / September 2003

Tip: Looking for answers? Try searching our database.

Problem serializing custom exception type deriving from System.Exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Alexander - 11 Sep 2003 00:16 GMT
I've created a new exception w/ a few properties specific to an app I want this this exception to be a part of. Whenever I attempt to serialize the exception I get something resembling the following error:

System.InvalidOperationException: There was an error reflecting type 'StoneAge.Media.QuoteProcess.LeadRouting.LeadQueueException'. ---> System.InvalidOperationException: The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes. Consider using imperative asserts or demands in the property accessors.

Below is a dump of the stack trace:

Service cannot be started. System.InvalidOperationException: There was an error reflecting type 'StoneAge.Media.QuoteProcess.LeadRouting.LeadQueueException'. ---> System.InvalidOperationException: The property 'TargetSite' on type 'System.Exception' cannot be serialized because it is decorated with declarative security permission attributes. Consider using imperative asserts or demands in the property accessors.
  at System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo)
  at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
  at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns)
  at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns)
  at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns)
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, Boolean repeats)
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, Boolean repeats)
  at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace)
  at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
  at System.Xml.Serialization.XmlSerializer..ctor(Type type)
  at StoneAge.ObjectUtility.ConvertObjectToXML(Object Source)
  at StoneAge.ObjectUtility.ConvertObjectToDynamicHTML(Object Source)
  at StoneAge.Media.QuoteProcess.LeadRouting.Log.Error(LeadQueueException exception)
  at StoneAge.Media.QuoteProcess.LeadRouting.QueueEngine.LoadQueue()

I've seen this issue on a few different newsgroups and message boards as well as on MS support at http://support.microsoft.com/default.aspx?scid=kb;en-us;326971. This is apparently a known issue w/ using the XmlSerializer class on a class with declaritive security.

One approach I've tried to get around this is to both decorate my derived exception w/ the SerializeableAttribute class and also have the derived exception implement ISerialable and provide my own implentation of GetObjectData that doesn't even touch the properties of the base Exception type. Looking at the stack trace though, GetObjectData is never called and XmlSerializer is using it's own mechanics for serializing the type.

Has anyone discovered a work around for this problem or have an alternative solution they might suggest? Thanks!

- James
Chris Taylor - 14 Sep 2003 22:51 GMT
Hi,

The GetObjectData which is part of the ISerializable interface is not used
for XmlSerializer, for that you should use the Binary or SOAP Formatters.
And when using the ISerializable interface, remember to implement the
Constructor that takes SerializationInfo and StreamingContext, this is also
required when implementing ISerializable.

Hope this helps

Chris Taylor

I've created a new exception w/ a few properties specific to an app I want
this this exception to be a part of. Whenever I attempt to serialize the
exception I get something resembling the following error:

System.InvalidOperationException: There was an error reflecting type
'StoneAge.Media.QuoteProcess.LeadRouting.LeadQueueException'. --->
System.InvalidOperationException: The property 'TargetSite' on type
'System.Exception' cannot be serialized because it is decorated with
declarative security permission attributes. Consider using imperative
asserts or demands in the property accessors.

Below is a dump of the stack trace:

Service cannot be started. System.InvalidOperationException: There was an
error reflecting type
'StoneAge.Media.QuoteProcess.LeadRouting.LeadQueueException'. --->
System.InvalidOperationException: The property 'TargetSite' on type
'System.Exception' cannot be serialized because it is decorated with
declarative security permission attributes. Consider using imperative
asserts or demands in the property accessors.
  at System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo
propertyInfo)
  at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo
memberInfo)
  at
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Struc
tModel model, String ns)
  at
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Struc
tModel model, String ns)
  at
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(Struc
tModel model, String ns)
  at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
  --- End of inner exception stack trace ---
  at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
  at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel
model, XmlRootAttribute root, String defaultNamespace)
  at System.Xml.Serialization.XmlSerializer..ctor(Type type, String
defaultNamespace)
  at System.Xml.Serialization.XmlSerializer..ctor(Type type)
  at StoneAge.ObjectUtility.ConvertObjectToXML(Object Source)
  at StoneAge.ObjectUtility.ConvertObjectToDynamicHTML(Object Source)
  at StoneAge.Media.QuoteProcess.LeadRouting.Log.Error(LeadQueueException
exception)
  at StoneAge.Media.QuoteProcess.LeadRouting.QueueEngine.LoadQueue()

I've seen this issue on a few different newsgroups and message boards as
well as on MS support at
http://support.microsoft.com/default.aspx?scid=kb;en-us;326971. This is
apparently a known issue w/ using the XmlSerializer class on a class with
declaritive security.

One approach I've tried to get around this is to both decorate my derived
exception w/ the SerializeableAttribute class and also have the derived
exception implement ISerialable and provide my own implentation of
GetObjectData that doesn't even touch the properties of the base Exception
type. Looking at the stack trace though, GetObjectData is never called and
XmlSerializer is using it's own mechanics for serializing the type.

Has anyone discovered a work around for this problem or have an alternative
solution they might suggest? Thanks!

- James

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.