xmlserializer

.NET OutOfMemoryException on XMLSerializer.Serialize

别等时光非礼了梦想. 提交于 2019-12-12 07:35:32
问题 I have a web site that is throwing OutOfMemoryExceptions on whenever it gets to the following spot in my code: XmlSerializer xs = new XmlSerializer(t, xoverrides); Seeing how this only happens when it is on the web server, i don't have a ton of information on why this is happening. I know that the objects that it is serializing aren't anything too serious-- definitely less than a MB each. Have you had this before? Feel like helping me diagnose the issue? Any help is appreciated. Thanks! 回答1:

C# Escaping XmlType Name with special char within XmlType() Attribute

▼魔方 西西 提交于 2019-12-12 04:32:37
问题 i need to implement and SOAP Service without using the WSDL (because its broken and will not be fixed). Now im stuck at a point where i need to set type attributes for some classes (base classes and derived one) normaly ill decorate my DTOs like this: BaseClass: [XmlInclude(typeof(Person))] [XmlType("Partner", Namespace = "http://....")] public abstract class Partner {...} and the DerivedOne: [XmlType("Person")] public class Person : Partner {...} the result looks like this: <tar:Partner xsi

XmlSerializer in C#, deserialize a class decorated with multiple XmlElement with same name by a particular attribute?

大兔子大兔子 提交于 2019-12-12 04:22:27
问题 I have a class which is decorated with XmlElement in a wrong way, but it has also attributes that could allow me to identify the fields I need. I can only modify [IWantToSerializeThisAttribute] and add other attributes to MySerializableClass because any modification to property names or XmlElement names would involve heavy coding maintenance. Here's how the class has been defined: [XmlRoot("ARandomXmlRoot")] public class MySerializableClass { //CAMPI DIR_DOCUMENTI //[MetadatoDocumentoAlfresco

Why is InvalideOperationException thrown when I try to serialize to XML an ObservableCollection containing hierarchical elements?

心不动则不痛 提交于 2019-12-12 04:07:11
问题 I write WPF MVVM modular application using Prism 6 in MS VS 2015 Professional. When I try to serialize to XML file the hierarchical ObservableCollection using System.Xml.Serialization.XmlSerializer then System.InvalidOperationException is thrown in System.Xml.dll. Below is definition of the collection: public class Group : ProfileElementType { . . . . . . private ObservableCollection<ProfileElementType> _childProfileElenents; [Browsable(false)] public ObservableCollection<ProfileElementType>

C# XmlSerializer fails on deserialization of an empty enum list if it's in an xmlattribute

╄→尐↘猪︶ㄣ 提交于 2019-12-12 02:42:43
问题 This is a note to my future self, and for the benefit of others. The described behavoir is NOT obvious... I've got this bit of C#: public enum Choices { One, Two, Three, } public class Element { List<Choices> _allowedChoices; [XmlAttribute] public List<Choices> AllowedChoices { get {return _allowedChoices ?? ( _allowedChoices = new List<Choices>() );} set { _allowedChoices = value; } } } [Test] public void testing_empty_enum_list_serialization() { var ser = new XmlSerializer(typeof (Element))

Use of DOM/SAX instead of XmlSerializer over HttpWebResponse

谁说胖子不能爱 提交于 2019-12-12 02:38:48
问题 I would like to use SAX/DOM parser in this below code to read a xml in HttpWebResponse instead of using XmlSerializer. Please help me how to do it? HttpWebRequest request = WebRequest.Create(requestURI) as HttpWebRequest; request.Credentials = _cred; WebResponse response = request.GetResponse(); XmlSerializer ser = new XmlSerializer(typeof(MyXMLClass)); myXMLClassObj = ser.Deserialize(response.GetResponseStream()) as MyXMLClass; 回答1: HttpWebRequest request = WebRequest.Create(requestURI) as

xmlns namespace resilency

☆樱花仙子☆ 提交于 2019-12-12 02:33:55
问题 I receive data from a server as utf-8 encoded xml messages that look like <?xml version="1.0" encoding="utf-8"?> <Data namespace="http://example.com/data"> ... </Data> The noteworthy thing about the example is that the "namespace" qualifier should in reality be the "xmlns" qualifier specifying the default xml namespace. The code for serialization / deserialization was (auto-) generated from a schema definition file, and both the xsd as well as the documentation that came along with it pretty

How to remove empty namespace attribute on manually added xml string when serializing object?

天涯浪子 提交于 2019-12-12 01:57:44
问题 I am using XmlSerializer to output my object model to XML. Everything works very well but now I need to add several lines of pre-built XML to the object without building classes for each line. After lots of searching, I found that I can convert the xml string to an XmlElement using XmlDocument's LoadXml and DocumentElement calls. I get the XML I want except that the string section has an empty namespace. How can I eliminate the empty namespace attribute? Is there a better way to add an xml

Xsd.exe generated class doesn't serialize mandatory elements when null value

随声附和 提交于 2019-12-12 01:51:33
问题 In the following XSD all elements are mandatory: <?xml version="1.0" encoding="utf-16"?> <xs:schema xmlns="http://TestNamespace" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://TestNamespace" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Test"> <xs:complexType> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" name="Id" type="xs:int" /> <xs:element minOccurs="1" maxOccurs="1" name="EMail" type="xs:string" /> </xs:sequence> </xs:complexType> <

c# XML deserialization of 1 XML to different classes

倖福魔咒の 提交于 2019-12-11 18:31:26
问题 I would like to manage multiple customer standards efficiently. If I open (deserialize) an XML, I want to determine which classes are used during deserialisation. Choosing another class basically means looking at the XML from an other perspective (view). What I have right now: I have a class Project which has some properties and methods. I am able to serialize instances of motor to XML, this works fine. Also deserialization works fine. Now I create a new class ProjectCustomerA , which is