4,685 questions
0
votes
0
answers
39
views
mlSerializer: "Types 'Base.ClassTest' and 'Message1_0.ClassTest' both use the XML type name 'ClassTest'" when serializing inherited classes
I am working with XML serialization in C# where I have multiple versions of a message class that inherit from each other.
Here’s a simplified version of my code:
namespace XMLSerializeProblem.Base
{
...
1
vote
1
answer
82
views
Serializing a value object to XML and back with DataContractSerializer
I'm working with a .NET 8 codebase that uses DataContractSerializer to convert an object model into XML and back again (for storing in a file system). At the moment, none of the classes used in the ...
1
vote
1
answer
50
views
Why does using XmlElement mess up serialization?
I need to generate some .xml given an example file. I notice that some of the nodes break convention and are camelCase instead of PascalCase. I'd like my code models to keep good conventions, but ...
0
votes
0
answers
43
views
Seralizing multiline text from XML with XmlSerializer and newlines
I have a C# class that includes a string property:
public string Location { get => _Location; set => _Location = value; }
private string _Location;
I use XmlSerializer for reading and writing ...
0
votes
2
answers
56
views
C#.NET XML Serialization: XMLAttribute is not setting NameSpace and only Password Element within UserName Object is having Attribute
I am trying to generate this Soap XML:
<soapenv:Envelope xmlns:bsvc="urn:com.workday/bsvc" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0....
1
vote
1
answer
65
views
Why XmlSerializer.UnknownAttribute/UnknownNode event raised when deserializing child classes?
I have been having problem with deseriailizing XML code genereated by XmlSerializer when child classes are used. The UnknownAttribute and UnknownNode events triggers and I assumed there was an error ...
0
votes
2
answers
71
views
Get rid of xsi:type and use tag names instead
I have some derived classes to serialize to XML:
public void Main()
{
LevelCollection collection = new LevelCollection();
collection.Add(new SubLevel1("aaa"));
...
0
votes
1
answer
37
views
Serialize documents with the same name but different properties into one class
I'm trying to read two Aux files with one class, but I'm having trouble.
I'm getting an error when I try to serialize my class. The xml schema is defined by a third-party and I can't change it.
The ...
0
votes
3
answers
123
views
Is there a good way to handle XML deserialization of files that can have nested nodes with variable names within C#?
I am working on a deserializer in C# for an XML file type for a program I don't have any control over. Unfortunately, the XML file structure completely breaks conventions in two major ways, as far as ...
1
vote
1
answer
116
views
C# - How can I (de)serialize internal classes (from)to XML with attributes?
I want to (de)serialize internal classes.
internal class Data
{
public string? Name { get; set; }
public string? Type { get; set; }
public List<DataWithAttribute> DataList { get; set;...
0
votes
0
answers
166
views
XmlSerializer unable to resolve assembly at constructor
I am calling the following constructor:
var serializer = new XmlSerializer(typeof(List<Slot>));
and end up with this exception in the log :
Unable to resolve assembly System.Private.CoreLib....
2
votes
1
answer
48
views
C# Serialization hide array name of list containing sub classes
My goal is to output XML like the sample below:
<FunctionList name="list1">
<Space title="RoomA">
<Space title="Cabinet1">
<Device title="...
1
vote
1
answer
81
views
How to Handle Optional Xml Elements using C++ boost::serialization
I'm using C++ boost::serialization library to read and write configuration XMLs. To provide backward compatibility to the user, while reading an XML if some XML elements are absent, it needs to have ...
0
votes
0
answers
109
views
ASP.NET Core use dependency injection for custom type in xml output formatter
In my ASP.NET Core project, I have a custom type which needs to be serialized using some external service:
public struct MyCustomType
{
private int value;
public MyCustomType(int value) { ...
0
votes
1
answer
159
views
XML Serialisation - dynamic namespace of root node
This is my class:
[XmlRoot(ElementName = "Package")]
public class Package<T>: MyBase
{
public Messages<T> Messages
{
get { return _messages; }
set { ...
-1
votes
1
answer
102
views
Insert a tag in the serialization of an xml file
I am serializing an XML file with the classes created automatically with paste special of an XML. I did everything without problems, more than 3,000 lines (and the Xml file more than 600), but I have ...
0
votes
1
answer
97
views
Boost serialization with empty container
I am using boost ( 1.69.0 ) serialization to generate an XML template file.
The result I want to achieve is unfortunately bad.
This is example code:
struct A
{
struct B
{
int bInt;
...
1
vote
1
answer
184
views
C# XmlSerializer - output multiple xml fragments controlling new lines
I want to be able to write fragments of indented XML with no namespaces, no XML preambles, and \n for line endings, using XmlSerializer for each fragment and using a single XmlWriter instance for all ...
0
votes
1
answer
46
views
XmlSerializer skipping items in non-pretty format xml
In case my xml file has the non-pretty format:
<ArrayOfColumn><Column><COLUMN_NAME>SomeName1</COLUMN_NAME></Column><Column><COLUMN_NAME>SomeName2</...
0
votes
1
answer
85
views
Prevent positional record from being serialized by XmlSerializer
I have simple C#9 positional record with an empty constructor (in addition to primary one):
public record FiscalTag(int Code, string Value, List<FiscalTag> ChildTags)
{
public FiscalTag() : ...
0
votes
1
answer
67
views
Infinite loop during XML file serialization (java.beans)
In the process of serializing to XML file, I'm encountering an infinite loop issue. I'm using java.beans, and through XMLEncoder, I'm attempting to serialize three classes: Category, Contact, and ...
1
vote
1
answer
164
views
Trouble Deserializing/Serializing XML with Mixed Element Order in C#
I am facing an issue while deserializing/serializing XML into a C# object. The XML structure has mixed order of elements, and I am encountering problems with elements that have the same name but ...
0
votes
1
answer
104
views
C# Serialize PSCredential to XML with XmlSerializer
Experienced with PowerShell, but new to C#.
I am creating a Binary PowerShell Cmdlet and have run into an issue when trying to serialize PSCredential to XML with the XmlSerializer.
When I serialize ...
0
votes
0
answers
25
views
Serialize XML to different object
I have two types of file XML that share some common information but also have some specialization:
<Source Alias="Hrc">
<Variable HandleType="Ext.Poll">
<Id&...
1
vote
2
answers
311
views
XmlSerializer crashes when encountering xml attribute (namespace)
Im trying to Deserialize a XML im getting from a service.
But the XmlSerializer failes when encountering the first attribute.
My shortened xml looks like this:
<?xml version="1.0" ...
0
votes
1
answer
37
views
Why does my XML deserialization only recognise the first contained object tag
I have the following classes:
public interface IVariable
{
string Name { get; }
dynamic Value { get; set; }
}
public class Namespace : IVariable, IXmlSerializable, IEnumerable<IVariable>...
2
votes
1
answer
212
views
How to Serialize/Deserialize an unordered_map member of a derived Class
So I'm building a simulated file-system in C++ to study the language better and maybe some system level programming. Im using Boost::Serialization to save the state of the file system when the user ...
0
votes
0
answers
52
views
Collection attributes are not serialized to xml [duplicate]
I have a custom serializable generic collection, defined (a simplified example) like this:
[Serializable]
public class ArrayOfItems<T> : IEnumerable<T>
{
[XmlAttribute("Setting&...
-1
votes
1
answer
79
views
C# how to deserialize XML string which has nested same node [duplicate]
<n-hierarchy>
<n name="ABC" n_id="971" />
<n name="XYZ" n_id="972">
<n name="jkl" n_id="973">
...
0
votes
0
answers
781
views
C# XML Serialization: Seralizizing Nullable Value Types (Want to Suppress "null" Values Without Decorators/Attributes/ShouldSerialize)
I'm working with code in C# trying to serialize an object to XML. I cannot add XML attributes or extra properties (e.g. bool ShouldSerializeFoo) to this object. Nor can I add any [Xml*] attributes to ...
0
votes
0
answers
71
views
WCF CreateMessage fails on escaped ASCII characters
I am migrating a WCF client application from DotNet Framework to DotNet (Core) 7. The object I am using serializes using ASCII character 0x07 as a separator, which under DotNet Framework would be ...
0
votes
0
answers
99
views
How to automatically deserialize a file that was serialized using BinaryFormatter?
Problem
I have a large file that was serialized using BinaryFormatter that I need to create a class for, so that I can serialize similar files.
What I have tried
I came across this answer that ...
0
votes
2
answers
102
views
How can I serialize 24 hours time to / from XML using C#?
I know how to serialize a "Date" to / from XML using C#:
[XmlElement(DataType ="date")]
public DateTime LastInvited { get => _LastInvited; set => _LastInvited = value; }
...
0
votes
2
answers
344
views
How to generate with java a xml with CDATA on a specific field
I would like to update an old piece of code, but I can't find the correct way to do it with the new system suggested from the deprecated class XmlSerializer, it was deprecated in Xerces 2.9.0. and it ...
0
votes
1
answer
608
views
Unclear why this Swagger UI fails with 'FormatterNotFoundException' exception only for this specific property
How to make the example working in Swagger while still having [Produces("application/json", "application/xml")] definition in controller method.
In .Net Core 6 API, have set up ...
0
votes
2
answers
55
views
IXmlSerializable ignores other properties during deserilization
I have a class implements IXmlSerializable, after ReadXml been called, the deserialization process returns and ignore other properties.
The xml file is completed, but when deserial it, only the first ...
0
votes
0
answers
25
views
How can I selectively return full XML properties in one method and partial in another using the same C# class?
I have a problem with serialization c# in .net
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
Is possible to control ...
0
votes
2
answers
62
views
How to convert string xml into C# Object reading only inner part of the document [duplicate]
I am working on an application where I need to convert string XML into C# object but I am receiving following error.
There is an error in XML document (1, 23)
InvalidOperationException: was not ...
1
vote
1
answer
93
views
Deserializing legacy XML class types into new class types
I'm supporting a legacy, internal API that uses two classes that are serialized using XML. Both classes are sub-classes of a common base class:
namespace My.Namespace {
[
Serializable,
...
0
votes
1
answer
264
views
How to create CDATA sections with the xsdata library?
I'm working on creating service that talks with Finn API, that requires XML instead of JSON.
Based on *.dtd file and xsdata library I generated classes that allows me to build an request object and ...
0
votes
0
answers
230
views
C# - Serializing to XML information as to which function to bind a delegate too
I need to be able to save a delegate with the information of which function it is connected to. Something like this:
In C#:
public class Skill
{
[XmlAttribute("SkillFunction")]
...
1
vote
1
answer
223
views
XML Serialization Namespace both Child and Parent Elements
Good day all,
I have trouble adding namespaces correctly to my XML. Both the parent and child elements have the own namespaces. When restructure the code I have gotten mixed results. My sample code ...
1
vote
0
answers
42
views
IXmlSerializable struct throws InvalidProgramException on Deserialize()
I have a pretty simple console application. Ignoring missing checks, the program is as follows:
using System.Drawing;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
...
1
vote
1
answer
37
views
DateTimes near a DST changeover do not accurately survive a WriteXML/ReadXML roundtrip. How to preserve them?
I recently had an issue that I traced to the fact that when I serialize/deserialize a DataSet to and from XML using WriteXML/ReadXML at very specific times near a DST changeover, the DateTimes are not ...
-1
votes
1
answer
368
views
Deserializing XML-file with SOAP-envelope and invalid xsd-address
I want to deserialize this kind of XML-files that have SOAP-envelope and invalid .xsd address in the header that doesn't exist anymore (finvoiceack.xsd). Would like to get the nodes to dataset or into ...
0
votes
3
answers
243
views
C# Serializing an object into XML that includes a list of objects
I need to serialize an XML to attach for an API PUT request.
I am using System.Xml.Serialization.
The end result needs to resemble the following:
<?xml version="1.0" encoding="UTF-8&...
1
vote
1
answer
1k
views
C# Deserialization of xml file returns "'There is an error in XML document (1, 2).'" error
I'm trying to deserialize an xml response I get from a call.
I've used Visual Studios "Paste Special" function to prepare my program for how the file is gonna look, and the only change I've ...
0
votes
1
answer
333
views
Can I make XmlSerializer in .NET 6+ accept a NULL character?
Consider the following minimal example (fiddle):
using System;
using System.IO;
using System.Xml.Serialization;
public class Program
{
public class C { public string S { get; ...
-2
votes
1
answer
793
views
Dynamic XML serializer in C#
Passing the root to the xsd.exe, successfully generates the Classes with the proper structure according to the XSD,
we can now assign values to the objects of those classes and populate them, the ...
1
vote
0
answers
150
views
Is there a way to validate that the xml serialization attributes on my classes and properties conform to an xsd schema?
Is there a built-in (or 3rd party) mechanism/library/analyzer that can be used to validate that the xml serialization attributes on a class/property matches the schema.
I know that you can't do full ...