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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:49:41+00:00 2026-05-24T02:49:41+00:00

I’m using the WCF WebApi stack (Preview 4) via NuGet (pkg version 0.3.0) and

  • 0

I’m using the WCF WebApi stack (Preview 4) via NuGet (pkg version 0.3.0) and cannot seem to figure out how to “POST a POCO” using HttpClient.

Given the following:

Public Class MyInfo
    Public Property MyDate As DateTime
    Public Property MyId As Guid
End Class

...
Dim value = New MyInfo With {.MyDate = Today, .MyId = Guid.NewGuid()}

Using client as New HttpClient(baseUri)
    Using response = client.Post(requestUri, New ObjectContent(Of MyInfo)(value))
        ' Do stuff
    End Using
End Using
...

When the Post method is called, I get the following exception:

The 'XmlSerializer' serializer cannot serialize the type 'MyInfo'.

at Microsoft.ApplicationServer.Http.XmlMediaTypeFormatter.GetSerializerForType(Type type)
at Microsoft.ApplicationServer.Http.XmlMediaTypeFormatter.OnWriteToStream(Type type, Object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
at Microsoft.ApplicationServer.Http.MediaTypeFormatter.WriteToStream(Type type, Object instance, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
at Microsoft.ApplicationServer.Http.ObjectContent.WriteToStreamInternal(Stream stream, TransportContext context)
at Microsoft.ApplicationServer.Http.ObjectContent.SerializeToStream(Stream stream, TransportContext context)
at System.Net.Http.HttpContent.LoadIntoBuffer(Int32 maxBufferSize)
at System.Net.Http.HttpClientChannel.PrepareWebRequestForContentUpload(HttpWebRequest webRequest, HttpRequestMessage request)
at System.Net.Http.HttpClientChannel.CreateAndPrepareWebRequest(HttpRequestMessage request)
at System.Net.Http.HttpClientChannel.Send(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.Send(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.Send(HttpRequestMessage request)
at System.Net.Http.HttpClient.Post(Uri requestUri, HttpContent content)
at System.Net.Http.HttpClient.Post(String requestUri, HttpContent content)
...

This is using the NuGet 0.3.0 package.

I’ve tried adding <Serializable()> and even <DataContract()> to MyInfo, but that didn’t help. Am I just doing something wrong?

I found this post here on StackOverflow where it looks like someone is doing something similar to what I did above. I’ve even duplicated his work (guessing that his Machine object was a simple POCO like my MyInfo is) and ran into the same “cannot serialize” exception.

  • 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-24T02:49:42+00:00Added an answer on May 24, 2026 at 2:49 am

    I ended up finding the problem myself. I was missing the media type. I changed the Post method to look like:

    Using client as New HttpClient(baseUri)
        Using response = client.Post(requestUri, New ObjectContent(Of MyInfo)(value, "text/xml"))
            ' Do stuff
        End Using
    End Using
    

    and it started working. I guess that makes sense. For some reason, I thought that there was some sort of default media type precedence built-in so that you didn’t have to go out of your way to specify the media type each time. Maybe there is, but I’m still doing something wrong?

    Update:

    My original problem actually had nothing to do with the media type, even though that actually did fix/workaround the problem. The problem seems to happen when MyInfo is nested inside of a Module like this.

    Module Module1
    
        Sub Main()
            Dim value = New MyInfo With {.MyDate = Today, .MyId = Guid.NewGuid()}
            Dim payload As HttpContent = New ObjectContent(Of MyInfo)(value)
    
            Using client as New HttpClient(baseUri)
                Using response = client.Post(requestUri, New ObjectContent(Of MyInfo)(value))
                    ' Do stuff
                End Using
            End Using
        End Sub
    
        Public Class MyInfo
            Public Property MyDate As DateTime
            Public Property MyId As Guid
        End Class
    
    End Module
    

    Once MyInfo moved outside of the Module, the error no longer happens. It’s also worth noting that while the media type is no longer required to prevent the exception, the lack of it results in no Content-Type header, which may not fly server-side as the server may not know how to deserialize the message body. In my case, I needed to leave the media type in so that the request would include a Content-Type: application/xml header for the server’s sake.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.