.NET Framework 4 Client Profile + System.Web.dll?

15k views Asked by At

I'm currently developing an application for .NET 4 Client Profile, as this is the version that will be present on most home computers through Windows Update.

However, I cannot add a reference to System.Web.dll as it does not exist in this version - what should I do?

Is it a good idea to deploy System.Web.dll along with my application, or won't that work? I really need HTTP connections and all, so I cannot modify my application as a workaround. Is targeting my application to .NET 4 (no client profile) perhaps a possibility or will that just not work on computers with only the Client Profile?

4

There are 4 answers

1
Wim Coenen On BEST ANSWER

NET 4 Client Profile, as this is the version that will be present on most home computers through Windows Update

Not really. .NET 4 (client profile or not) currently isn't present on any pre-Windows 10 installation by default. For example, Windows 7 comes with .NET 3.5 SP1, not .NET 4.0. There may be a windows update, but it is optional.

Therefore, you might as well target the full .NET 4 framework.

The link between operating systems and .NET framework versions can be found here. The checkmarks indicate that a version is available out of the box, plus sign means it can be installed.

Also note that 4.5, 4.6 and 4.6.1 are all in-place updates, meaning that a system with any of those is also considered to have 4.0.

2
Filip Ekberg On

If you are targeting .NET 4.0 and not .NET 4.0 Client Profile you should add that as a prerequisite. This will allow it to be installed when you install your application.

You can still use Sockets if you run .NET 4.0 Client Profile, they are located in System.Net. You only want System.Web when the following applies:

The System.Web namespace supplies classes and interfaces that enable browser-server communication. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request; the HttpResponse class, which manages HTTP output to the client; and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control.

0
whyleee On

Even if you deploy the copy of the System.Web.dll to the client that won't solve the problem. And the problem is: you can't link to the assemblies compiled for .NET 4 profile (not client) from the assembly that compiled for .NET 4 Client profile. The only solution is to target your assembly to the not client profile.

The MSDN Page about .NET Framework Client Profile.

0
Brian On

If you are just wanting to use the HttpWebRequest, it is available in the client profile for .Net 4.

Here's an example that you can try, just create a new console app using the .Net 4 Client Profile and paste this into Program.cs...

using System;
using System.IO;
using System.Net;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var request = WebRequest.Create("http://google.com");
            var response = request.GetResponse();
            using (var s = response.GetResponseStream())
            using( var sr = new StreamReader(s))
            {
                Console.Write(sr.ReadToEnd());
            }

            Console.ReadKey();
        }
    }
}

You asked about HttpCookieCollection in one of your comments. It seems that HttpWebRequest uses a CookieContainer to store the cookies.