Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:55:51+00:00 2026-05-30T01:55:51+00:00

I try to add a simple test-class to a RestSharp-RestRequest via the RestRequest.AddBody -Method.

  • 0

I try to add a simple test-class to a RestSharp-RestRequest via the RestRequest.AddBody-Method. I tried to serialize using both of the delivered serializers, but i could not get one of them to work (JSON-Serializations works pretty fine with just the same settings…)

This is how i do the serialization:

private void SerializationTest()
{
    RestRequest request = new RestRequest();

    request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
    //request.XmlSerializer = new RestSharp.Serializers.XmlSerializer();

    request.RequestFormat = DataFormat.Xml;
    //request.RequestFormat = DataFormat.Json;
    request.AddBody(new Dummy()); // uses JsonSerializer

    label1.Text = request.Parameters[0].Value.ToString();
}

The dummy-class I’m using is:

private class Dummy
{
    public string A = "Some string";
    public string B = "Some string";
}
  1. Using RestSharp.Serializers.XmlSerializer() I get: “<Dummy />” (missing both strings)

  2. Using RestSharp.Serializers.DotNetXmlSerializer() I get nothing, the programm just dosen’t get over the serialization-step.

  3. Using JSON request.RequestFormat = DataFormat.Json;, everything works fine.

.

{  
    "A": "Some string",  
    "B": "Some string"  
}

How do i get the class so serialize proper to XML?
Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:55:52+00:00Added an answer on May 30, 2026 at 1:55 am

    Those are fields, not properties. The underlying XmlSerializer only looks for public properties. Update it to this and it should work:

    class Dummy
    {
        public string A { get; set; };
        public string B { get; set; };
    
        public Dummy() {
            A = "Some string";
            B = "Some string";
        }
    }
    

    The reason the JSON one works is because it defers to JSON.NET’s default serializer which (apparently) supports fields. I think this is the wrong design decision personally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to add a class to a td-element using javascript with the internet
I've tried the add() method but nothing is displayed when I try to add
I try to add an addons system to my Windows.Net application using Reflection; but
I try to proxy existing Python class to Objective-C. I started from simple sample
I tried to serialize a DynamicObject class with BinaryFormatter , but: Output file is
My IDE crashes any time I try add a new component to the toolbar.
I try to add dots between the page title and the page number in
I try to add Message.framework to my project frameworks directory. After that I compile
Whenever I try to add a new project to my SourceSafe repository it creates
If I try to add a tab to the toolbox and name it 'Clipboard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.