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 9133153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:26:17+00:00 2026-06-17T08:26:17+00:00

I am writing a simple API using .Net’s Web API. I have defined the

  • 0

I am writing a simple API using .Net’s Web API. I have defined the following Model:

public class VehicleUpdate
{
    [Required(ErrorMessage = "DealerID Required")]
    public int DealerID { get; set; }

    [Required(ErrorMessage = "VIN Required")]
    [StringLength(17, ErrorMessage = "VIN Must be 17 characters", MinimumLength = 17)]
    public string VIN { get; set; }

    [StringLength(8000, ErrorMessage = "Comments must be less than 8,000 characters")]
    public string Comments { get; set; }

    public double Retail { get; set; }
}

I tried to test it by doing an HTTP Post with the following XML

<VehicleUpdate>
    <DealerID>30</DealerID>
    <VIN>1FMRU17L0WLA62356</VIN>
    <Comments>This is a test.</Comments>
    <Retail>1000</Retail>
</VehicleUpdate>

When I do this, I get the following SerializationException:

System.Runtime.Serialization.SerializationException: Error in line 1
position 16. Expecting element ‘VehicleUpdate’ from namespace
‘http://schemas.datacontract.org/2004/07/API.Models&#8217;.. Encountered
‘Element’ with name ‘VehicleUpdate’, namespace ”. at
System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator
xmlReader, Boolean verifyObjectName, DataContractResolver
dataContractResolver) at
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator
reader, Boolean verifyObjectName, DataContractResolver
dataContractResolver) at
System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlReader
reader) at
System.Net.Http.Formatting.XmlMediaTypeFormatter.<>c_DisplayClass3.b_2()

Can someone please tell me what I am doing wrong? I thought this would be a valid XML message.

  • 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-06-17T08:26:18+00:00Added an answer on June 17, 2026 at 8:26 am

    Two things:

    AS the error says, DataContractSerializer expects the XML to provide a proper namespace, and your XML doesn’t have it.
    You can either pass the namespace:

    <VehicleUpdate xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/API.Models">
     // properties
    </VehicleUpdate>
    

    Or switch to XmlSerializer in your Web API configuration:

    config.Formatters.XmlFormatter.UseXmlSerializer = true;
    

    Then you can pass the exact XML you are passing now.

    You might run into another issue, when using [Required] on non nullable type i.e. int. This is a known problem since int will be always 0 instead of null if not passsed. In that case you might have to change your model to have excplicit DataContract definition:

      [DataContract]
        public class VehicleUpdate
        {
            [DataMember(IsRequired = true)]
            [Required(ErrorMessage = "DealerID Required")]
            public int DealerID { get; set; }
    
            [DataMember]
            [Required(ErrorMessage = "VIN Required")]
            [StringLength(17, ErrorMessage = "VIN Must be 17 characters", MinimumLength = 17)]
            public string VIN { get; set; }
    
            [DataMember]
            [StringLength(8000, ErrorMessage = "Comments must be less than 8,000 characters")]
            public string Comments { get; set; }
    
            [DataMember]
            public double Retail { get; set; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple proof-of-concept web service using ASP.NET MVC3 controller with JSON
I am writing a Web Api (using asp.net Web Api) and naturally want clients
I have been using the ZipPackage-class in .NET for some time and I really
I'm writing a pythonic web API wrapper with a class like this import httplib2
I am writing a Web API using MVC4 that should be consumed by multiple
I'm using Webex's URL API and for some reason, when writing a simple PHP
I'm writing a program using the Winsock API because a friend wanted a simple
I am writing a very simple proxy wrapper for the reddit api so I
What's the best API I can use to do some simple XML read/writing? I'm
I am writing simple parallel program in C++ using OpenMP. I am working on

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.