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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:09:21+00:00 2026-05-20T13:09:21+00:00

I’m trying to learn C#/Silverlight/Windows Phone 7. What’s going on here: When I try

  • 0

I’m trying to learn C#/Silverlight/Windows Phone 7. What’s going on here: When I try to use examples straight off of MS’s MSDN site, and I get all kinds of errors:

For example:

using System;
using System.IO;
using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Device.Location;
using Microsoft.Phone.Reactive;

  private void registerPhone(object sender, RoutedEventArgs e)
    {

        // Create a request using a URL that can receive a post. 
        WebRequest request = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx ");
        // Set the Method property of the request to POST.
        request.Method = "POST";
        // Create POST data and convert it to a byte array.
        string postData = "This is a test that posts this string to a Web server.";
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        // Set the ContentType property of the WebRequest.
        request.ContentType = "application/x-www-form-urlencoded";
        // Set the ContentLength property of the WebRequest.
        request.ContentLength = byteArray.Length;
        // Get the request stream.
        Stream dataStream = request.GetRequestStream();
        // Write the data to the request stream.
        dataStream.Write(byteArray, 0, byteArray.Length);
        // Close the Stream object.
        dataStream.Close();
        // Get the response.
        WebResponse response = request.GetResponse();
        // Display the status.
        Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        // Get the stream containing content returned by the server.
        dataStream = response.GetResponseStream();
        // Open the stream using a StreamReader for easy access.
        StreamReader reader = new StreamReader(dataStream);
        // Read the content.
        string responseFromServer = reader.ReadToEnd();
        // Display the content.
        Console.WriteLine(responseFromServer);
        // Clean up the streams.
        reader.Close();
        dataStream.Close();
        response.Close();

    }

It tells me

1) The name 'Encoding' does not exist in this context

2) System.Net.WebRequest does not contain a definition for GetStreamRequest and no extension method GetRequestStream accepting a first argument of type System.Net.WebRequest could be found (are you missing a using directive... etc

3) a similar message for ContentLength

4) a similar message for GetResponse

I have no idea what libraries I need to be “using” and even when I think I’m “using” the right ones, it gives me errors. What am I doing wrong?

  • 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-20T13:09:21+00:00Added an answer on May 20, 2026 at 1:09 pm

    The Encoding class resides in the System.Text namespace. You have to add that to the “usings”.

    As far as for the other messages, this has to do with the limitations of Silverlight. The MSDN samples, I presume, were taken from the “big” version of .NET Framework, weren’t they?

    In Silverlight, you see, some things are not allowed in order to prevent undesirable application behavior (such as blocking calls), and some things are not supported due to resources limitation.

    In particular, ContentLength is one of the latter. The library will determine the content length based on the actual amount of data you write into the request. Just remove that line, you’ll be ok.

    But GetResponseStream() is actually one of the former. It has to do with the fact that this operation implies actually opening network connection, which may take a while. And since blocking calls are not allowed in Silverlight, the GetResponseStream() method also has to go.

    Instead, you’re supposed to use the so-called “asynchronous pattern” – that is, the pair of methods BeginGetResponseStream/EndGetResponseStream. You do it by calling the Begin method and providing a callback that will be called once the operation is complete. Then, inside that callback, you use the End method to get the result of the operation. Like so:

                request.BeginGetRequestStream( ar =>
                {
                    var dataStream = request.EndGetRequestStream( ar );
    
                    // Write the data to the request stream.
                    dataStream.Write( byteArray, 0, byteArray.Length );
                    // Close the Stream object.
                    dataStream.Close();
    
                    // and so on...
    
                }, null );
    

    Same goes for the GetResponse method.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.