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