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

  • Home
  • SEARCH
  • 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 8217777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:34:06+00:00 2026-06-07T12:34:06+00:00

I am doing some simple testing of the new ASP.NET Web API, and I

  • 0

I am doing some simple testing of the new ASP.NET Web API, and I am experiencing the following problem when returning a serializable class or collection from my action method.

My class looks like this:

<Serializable()>
Public Class Test

    <XmlElement(ElementName:="Name")>
    Public Property Name() As String = String.Empty

    <XmlElement(ElementName:="ID")>
    Public Property ID() As String = String.Empty

    <XmlElement(ElementName:="ClassID")>
    Public Property ClassID() As String = String.Empty

End Class

My test action method to retrieve a single Test looks like this:

Public Function GetTest(ByVal id As String) As Test

    Dim newTest As Test = new Test() With {.ID = id, .Name = "My Test", .ClassID = System.Guid.NewGuid().ToString()}

    return newTest

End Function

When I view the results in the browser or in Fiddler as either XML or JSON, the property names of the returned Test class have had unserscores prepended to them, like so:

<Test>
    <_ClassID>88bb191d-414c-45a4-8213-37f96c41a12d</_ClassID>
    <_ID>ed853792-b7eb-4378-830b-1db611e12ec9</_ID>
    <_Name>Another Test</_Name>
</Test>

How do I get rid of the unwanted underscores on the element/property names?

Thanks!

  • 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-07T12:34:08+00:00Added an answer on June 7, 2026 at 12:34 pm

    You could use the DataMember attribute:

    Public Class Test
        <DataMember(Name:="Name")>
        Public Property Name() As String = String.Empty
    
        <DataMember(Name:="ID")>
        Public Property ID() As String = String.Empty
    
        <DataMember(Name:="ClassID")>
        Public Property ClassID() As String = String.Empty
    End Class
    

    After further investigation it seems that if you do the same thing in C#, no underscores are added and no need to use DataMember. It just works. So I guess this oughta be some VB.NET thingy thing.

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

Sidebar

Related Questions

I am doing some exercises and tried to convert a simple class into a
What am I doing wrong here: class Helo { // main: generate some simple
I've been doing some simple shaders and Im encountering an error that happens randomly,
I'm doing some fairly simple cross-platform TCP socket programming. I have unfortunately found out
i've been doing some research on interfaces and a simple layman's explanation for what
I'm having some trouble doing a very simple task. I have a rich textbox
I'm having some issues in doing a simple regex using sed. I've to do
I a doing a weird project, and looking to convert some short, simple datagrams
I've been doing some performance testing, mainly so I can understand the difference between
I'm doing some simple MS unit tests on my standard, nothing special controller. When

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.