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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:34:19+00:00 2026-05-24T17:34:19+00:00

In order to log some HTTP traffic I’m trying to serialize an instance of

  • 0

In order to log some HTTP traffic I’m trying to serialize an instance of System.Net.HttpWebRequest. The application uses MVC 3 and the problem code is in an action method in a controller class.

In .NET Framework 4 it the class is documented as serializable:

[SerializableAttribute]
  public class HttpWebRequest : WebRequest, 
      ISerializable

The following test code fails at the indicated statement:

...
HttpWebRequest preapprovalRequest = (HttpWebRequest)WebRequest.Create("http://big.URL.here");
...
HttpWebResponse preapprovalResponse = (HttpWebResponse)preapprovalRequest.GetResponse();


// Serialize the request context.
IFormatter formatter = new BinaryFormatter();
MemoryStream msRequest = new MemoryStream();
formatter.Serialize(msRequest, preapprovalRequest); //<<<<< Error here.
// Reset the stream and deserialize.
msRequest.Seek(0, SeekOrigin.Begin);
HttpWebRequest duplicateRequest = (HttpWebRequest)formatter.Deserialize(msRequest);
msRequest.Close();

// Serialize the response context.
MemoryStream msResponse = new MemoryStream();
formatter.Serialize(msResponse, preapprovalResponse);
// Reset the stream and deserialize.
msResponse.Seek(0, SeekOrigin.Begin);
HttpWebResponse duplicateResponse = (HttpWebResponse)formatter.Deserialize(msResponse);
msResponse.Close();

The error reported is:

Type 'System.Net.WebRequest+WebProxyWrapper' in Assembly
'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
is not marked as serializable.

I’ve tried chasing WebProxyWrapper with no joy. Just a bit of unhelpful baggage. Explicitly casting the HttpWebRequest to a WebRequest doesn’t alter the error:

formatter.Serialize(msRequest, (WebRequest)preapprovalRequest);

On the bright side, the code does properly serialize and deserialize the instance of HttpWebResponse.

How can I lose the wrapper? Is there a better approach?

  • 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-24T17:34:20+00:00Added an answer on May 24, 2026 at 5:34 pm

    The official answer from Microsoft:

    Thank you for your feedback. Unfortunately HttpWebRequest dropped
    support for serialization after .NET 1.1. See
    http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.httpwebrequest(v=VS.100).aspx

    We’ll see if we can get that attribute removed to avoid this confusion
    in the future.

    They changed the documentation to include the [ObsoleteAttribute] attribute.

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

Sidebar

Related Questions

I am currently working on a .Net application which makes HTTP requests to some
I'm trying to implement an IErrorHandler in my WCF service in order to log
I've got a rails application where users have to log in. Therefore in order
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary
am trying to connect to a web service in order to retrieve some data
I'm struggling with regex for splitting logs files into log sequence in order to
In order to debug an asp.net web app I have to have IE Script
I use the module mechanize in order to log in a site. When I
I'm trying to make an HTTP GET request using the jQuery get() function, but
I am porting a Python application to Android and, at some point, this application

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.