.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

XmlSerializer E|rror

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :Sql Server
 
on ReportServer Class
Microsoft.ReportingServices.RdlObjectModel.Report

XmlSerializer serializer = new XmlSerializer(typeof(Report))

ther is an error
System.InvalidOperationException was unhandled
InnerException: System.NotSupportedException
Message=Cannot serialize member Microsoft.ReportingServices.RdlObjectModel.Report

(c# 2010 Sql server R2)

tank's


View Complete Post


More Related Resource Links

XmlSerializer - how to define class to not generate attributes in root element?

  
Hi! I have simple class that I serialize to xml file: <?xml version="1.0" encoding="utf-8"?> <MyRootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Area="East">   <Products>     <SalesProduct Taxable="true">       <Name>Sofa</Name>     </SalesProduct>     <Product>       <Name>Television</Name>     </Product>   </Products> </MyRootElement> I don`t want have in xml file attributes xmlns:xsi and xmlns:xsd. How can I define class to not have these two attributes in xml file? I tried use XmlRoot attribute but there is no control for these two attributes. They are always generated. Regards

XMLSerializer don't handle mixed contents properly

  
mixed content model allows a combination of text and elements in the XML document. we use .net xmlserializer to serialize/deserialize the XML. XmlSerializer don't handle mixed content properly. XmlSerializer handles mixed content models to a degree. XmlSerializer add the text in the xml document, but the position of text is not exactly where they appeared in the original XML document. Let's take a example here is original xml <employee xmlns="http://example.org/xmlserializer">   here is some text...   <id>333-33-3333</id>   here is some more...   <name>Bob Smith</name>   and here is even more... </employee> We deserialize above xml using the xmlserializer then we serialize it back into xml. Now xml document is changed as follows <employee xmlns="http://example.org/xmlserializer">    <id>333-33-3333</id>   <name>Bob Smith</name>   here is some text...   here is some more...    and here is even more... </employee> You see the position of text is changed. I have seen the Microsoft code to serialize/deserialize the xml through reflector. They put text in a string array but position is not saved. Is there any solution or workaround? I don't want to parse the xml by xmlReader. I want fix in the Microsoft generated classes that ar

XmlSerializer crashes when vb6 instantiates it via COM

  
I Have a vb6 application that uses .net clases via COM. When one of this clases calls code which instantiates XmlSerializer vb6 aplication crashes. Just this line fails: Dim x as new XmlSerializer(GetType(CustomClass)) I agregate that these clases load assemblies dinamically but only it crashes over vb6 aplication. In .net 100% aplication this not happens. I don't know if this is the forum I should post this problems Thanks for your help.

Can serialize but not deserialize class containing an xs:list attribute using XmlSerializer

  
I have a simple serializable class along the lines of: [Serializable] [XmlType] public class MyClass { [XmlAttribute("values")] public int[] Values { get; set; } } If I create an instance of this class with Values set to an empty collection the XmlSerializer class produces this output as expected: <?xml version="1.0" encoding="utf-16" ?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" values="" /> However, deserializing this exact output throws a System.FormatException: Input string was not in a correct format. Shouldn't the XmlSerializer be able to deserialize this, since it produced the xml string in the first place?

Nesting serialized classes with XmlSerializer without escaped brackets

  
Hi The company I work for use a state implementation based on the XmlSerializer generic class in so far that we have state classes with simple public variables and no logic which we then use the XMLSerializer to serialize in in great extend nest. For instance class A has a Class B and a class C variable, each with a state class being serialized and put into a state class of the owner class. Is there any way outside actually implementing IXmlSerializable that I can allow to include XML directly in own output xml instead of escaping it when it meets brackets in strings for instance? The deal is that since all state classes individually are serialized simple classes, I know that they contain valid XML and that that will conform to the XMLDOM even if piecing them together and manually implementing the serializers will be quite time consuming even if limiting to the CSharp framework, but the multi layer escaped structure is awfull to the eye. See this simplified example: using System.Xml; using System.Xml.Serialization; using System; using System.IO; namespace TingTester { class Program { static void Main(string[] args) { var simpleser = new XmlSerializer(typeof(LittleStateClass)); string serialized = Serialize(GetSimpleVersion(), simpleser); Console.WriteLine("Simple elements contain no escapes: {0}", !serialized.Contains("&"

XmlSerializer: Serialize an array of System.Drawing.Color

  
Ok,  here is my problem... I am building a UI configuration tool that utiliizes a PropertyGrid.  One of the properties is a indexed list of Colors contained in an array: CategoryAttribute("Style"), DisplayName("Data Set Colors"), DescriptionAttribute(""), XmlArray("SetColors"), XmlArrayItem(ElementName="Color",Type=typeof(SColor))] public Color[] SetColors { get; set; } The beauty of the PropertyGrid is it knows how to handle this Poperty and properly handles array and list of Colors. BUT...   As we already know in order to serialize a Color,  we have to use a surrigate property,  which is very unfortunate, and I fear is one of those little thing MS just overlooked.  (I understand it is actually a structure and not a class and has not default properties from which to get type info from.) I am really amazed that when I do serialize the class,  the XML is soooo  close to what I need,  its just missing the actual color value data: <AppGridColumnConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Name>Label</Name> <SetColors> <Color /> <Color /> <Color /> </SetColors> <IsDefaultEditable>false</IsDefaultEditable> <IsDirtyCheck&

Problems with XmlSerializer and namespace

  
Hi, I am not sure if this is a bug or I am missing something obvious, but I'm having difficulty adding a default namespace when serializing an object using the XmlSerializer.Serialize() function. I am supplying the namespace with an XmlSerializerNamespaces object to the Serialize() function but it just seems to get ignored. Here is the code I am using with a simple example object called Car [Serializable()] public class Car { public Car() { } private string _color; public string Color { get { return _color; } set { _color = value; } } private int _doors; public int NumberOfDoors { get { return _doors; } set { _doors = value; } } private string _model; public string Model { get { return _model; } set { _model = value; } } private string _manufacturer; public string Manufacturer { get { return _manufacturer; } set { _manufacturer = value; } } } And here is the code that I am serializing to a string: //Example namespace to use string nmspace = "http://www.mynamespace.com/Car"; StringBuilder xmlString = new StringBuilder(); StringWriter sw = new StringWrite

Can XmlSerializer add attributes to an element?

  
I'm using XmlSerializer to serialise a c# object into XML.public class Letter{        [XmlElement]        public String AccountNumber { get; set; }}which gives:<Letter><AccountNumber>12345678</AccountNumber></Letter>What I'd like to be able to do is to add a flag as an attribute to say if the particular data element is encrypted, so the XML comes out as:<Letter> <AccountNumber encrypted="true">=S2Hgd3$eDF</AccountNumber> </Letter>Is it possible to add this encrypted flag easily using the XmlSerializer? Thanks for any advice!

MessageContract/XMLSerializer - Known Type not being named with its element name when passed as obje

  

Okay, I've just deleted my first post since I was having issues with editting a post with codeblocks.  Trying once more.

I'm new to WCF and I am trying to write a webservice that must follow a specific XML format.  Because of this, I found that I had to drop DataContractSerializer since I must be able to use attributes.  I now have the <XMLSerializerFormat> attribute on my servicecontract for this purpose and I have laid out the schema I need by using a Class with Public Properties and the <Serializable()> attribute where appropriate.  I have one service endpoint that has several different schemas that it may accept.  I have a base class with derived classes for this purpose.  This also works well from what I can see as the test client and webservice are talking to each other just fine.  However, the client that will be using the service is non-WCF and must have the elements named specifically in order to handle them.  The problem arises when the service is serializing the derived classes.  The structure of each class works perfectly, however, the name of the element is not the name of the element I have assigned it.  It is most likely because of the way that I pass the information back and forth to the service and the fact that I do not know what the object actually is when it is passed into or out o

XmlSerializer deadlock/timeout in .NET 2.0

  

I have experienced problems with the XmlSerializer in my application. Instantiating it causes a 10 minute timeout because the csc process seems to be deadlocked. The error is new since .NET 2.0.

The problem only occurs in a slave process, not in any of the main processes which are started directly as services or from the shell. So what special about the slave process? It's a .NET console application started fom a .NET service with Process.Start(), ShellExecute = false and RedirectStandardInput = true. The slave process reads commands from the master process in a background thread with Console.ReadLine(). In another background thread an XmlSerializer is instantiated and it fails. The error seems to be certain on machines with only one CPU and no hyper threading.

We have found a very curious workaround. The error does not occur If we omit reading from standard input in the slave or if we start the slave process with RedirectStandardInput = false! How can that influence csc.exe?

Any suggestions to the cause of the problem?

  • It occurred after we migrated to .NET 2.0.
  • It's certain on some machines and random on others.
  • The error occurs before any commands have been send from the master process.
  • The error does not occur if we omit Console.ReadLine().
  • The error does not occur if we start with RedirectSta

XMLSerializer Problem on typcasting a deserialized object

  

Hi,

I have little understanding problem with XMLSerialiyer.

It seams to be the way, that a serialized object can not be deserialized again if serialization and deserialization are called fromassemblies which are identical, but physically located on different paths. The following code shows the deserialization:

using (FileStream fs = new FileStream(settingsPath, FileMode.Open))
{
    XmlSerializer serializer = new XmlSerializer(typeof(MySettings));
    object o = serializer.Deserialize(fs);
    instance = o as MySettings;
}

The strange part is, that the object o shows all the properties of the MySettings class (in the debugger), but when I try to assign "o as MySettings" to instance instance stays null . So actually the deserialization seems to work, but the typcasting not.

Every thing works fine as long as it is the same application that created the xml file deserializes it. But in my case, where I wrote a test, using the same assemblys (partially loaded at runtime) then the application later on will show the described faulty behaviour.

What could be the cause to my problem?

Regards
Rainer

 


XMLSerializer Problem on typcasting a deserialized object

  

Hi,

I have little understanding problem with XMLSerialiyer.

It seams to be the way, that a serialized object can not be deserialized again if serialization and deserialization are called fromassemblies which are identical, but physically located on different paths. The following code shows the deserialization:

using (FileStream fs = new FileStream(settingsPath, FileMode.Open))
{
    XmlSerializer serializer = new XmlSerializer(typeof(MySettings));
    object o = serializer.Deserialize(fs);
    instance = o as MySettings;
}

The strange part is, that the object o shows all the properties of the MySettings class (in the debugger), but when I try to assign "o as MySettings" to instance instance stays null . So actually the deserialization seems to work, but the typcasting not.

Every thing works fine as long as it is the same application that created the xml file deserializes it. But in my case, where I wrote a test, using the same assemblys (partially loaded at runtime) then the application later on will show the described faulty behaviour.

What could be the cause to my problem?

Regards
Rainer

 


XmlSerializer and IList

  
Has someone found any workaround for this bug? It looks like the XmlSerializer cannot serialize a member of type IList<T>.

public class Program
{
    public class Order { }
    public class User
    {
        private IList<Order> _orders;
        public IList<Order> Orders
        {
            get { return _orders; }
            set { _orders = value; }
        }
    }

    static void Main(string[] args)
    {
        User user = new User();
        user.Orders = new List<Order>();
        user.Orders.Add(new Order());

        XmlSerializer serializer = new XmlSerializer(typeof(User));
        serializer.Serialize(Console.Out, user);
    }
}

The DataContractSerializer used in WCF handles correctly members of this interface but I am using it in a classic web service which uses XmlSerializer. Declaring the member as List<T> instead of IList<T> is not a solution for me.

Any suggestions are greatly appreciated,

Darin

XMLSerializer: Losing data from a generated web service proxy using svcutil

  

I generated a proxy using svcutil with the option ser:XmlSerializer.  When trying to serialize the object I am losing data.  The wsdl came from a .asmx web service.


xmlserializer is escaping < > : CDATA fields

  

Hello,

I'm trying to serialize a XML file, but the XmlSerializer is escaping characters '<' and '>' on CDATA fields.

 

The code that does it is following :

private void SerializeXml(TestSuite ts)
    {
      XmlSerializer xSeri = new XmlSerializer(typeof(TestSuite));
      StringBuilder sb = new StringBuilder();
      XmlWriterSettings xSettings = new XmlWriterSettings();
      xSettings.Encoding = Encoding.UTF8;
      xSettings.NewLineHandling = NewLineHandling.None;
      xSettings.OmitXmlDeclaration = true;
      //xSettings.OutputMethod = XmlOutputMethod.Xml;
      //xSettings.CheckCharacter = true;

          using (XmlWriter writer = XmlWriter.Create(sb, xSettings))
          {
            try
            {

              xSeri.Serialize(writer, ts);
            }
            catch (Exception e)
            {
              throw e;
            }

     

No element name appears after using XmlSerializer on a class implementing ICollection

  

Hi, 

I have the following issue: after serilizing my class CounterInfoCollection that implements ICollection It doesn't come up with the correct xml. I know I may solve it by using List<> instead but now that i have implemented ICollection (I did that assuming List<T> were not supported as it stated on the msdn that Arrays of two kinds including List<T> were not supported) I would like to solve it using ICollection.

Here is an example of my xml and classes:

<Place>myGarden</Place>
<CounterInfoCollection>
  <Ducks>34</Ducks>
  <Birds>23</StartValue>
</CounterInfoCollection>
<CounterInfoCollection>
  <Ducks>166</Ducks>
  <Birds>11</StartValue>
</CounterInfoCollection>

but i obviously want CounterInfoCollection to be CounterInfo and all items wrapped around CounterInfoCollection  like:

take for example the Classes CounterInfoCollection , CounterInfo and a Holder for holding the collection

 

[XmlRoot]
public class CounterInfoCollection : ICollection
{
  private ArrayList counterInfoArray = new ArrayList();

  [XmlElement("CounterInfo")]
  public CounterInfo this[int index]
  {
    get { return (CounterInfo) counterInfoArray[index]; }
  }

  public void CopyT
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend