Is there an explanation behind the error "The type or namespace name 'Script' does not exist in the namespace 'System.Web'"

15,054

Solution 1

Looks like your provider does not have the dll System.Web.Extensions in the GAC.

The namespace System.Web.Scripts is part of the System.Web.Extensions.dll.

You can solve your problem if you do.

  1. Select System.Web.Extensions in your project References
  2. Go to properties tab and set Copy Local to true

This ensures that you deploy this dll too.

enter image description here

enter image description here

Solution 2

Just add System.Web.Extensions as a reference to your project. You don't have to do it manually through web.config. Set Copy Local to true to make sure it is included in your distribution.

Solution 3

you can right click the project name/location in your web site project and choose Add Reference.... From there a dialog will display. Choose the .NET tab and select the System.Web.Extensions. This should add it to the project. You can do this for any namespaces that you need to add.

Share:
15,054
dochoffiday
Author by

dochoffiday

I like throwing things... mostly frisbees.

Updated on June 13, 2022

Comments

  • dochoffiday
    dochoffiday almost 2 years

    I made an "ASP.NET Empty Web Site" in Visual Studio Express 2010.

    On a code file in the App_Code, I have the line "using System.Web.Script.Serialization;"

    When I pushed the files to the server, I got the following error:

    Exception message: c:\inetpub[....]\Extensions.cs(10): error CS0234: The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

    (The server is running Windows Server 2008 with IIS 7 with ASP.NET 4.0 installed.)

    Since this is a web site, and not a web project, I couldn't use the "publish" feature as promoted here: The type or namespace name 'Script' does not exist in the namespace 'System.Web'

    Finally, after some digging, I figured out that this namespace is included in the System.Web.Extension assembly, and that I had to manually include it via the web.config:

    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </assemblies>
    </compilation>
    

    So, my question: is there a better way to go about this?

    Since none of this is needed on my local project, how can I first determine what assemblies I'll need to reference manually, and second, how can I get the information required to do the referencing (i.e., how do I get the PublicKeyToken)?

    UPDATE

    Because this is a Web Site and not a Web Project, my list of references does not show up until after I add them to the Web.Config manually.

    So, to select "Copy Local" to "true" does not work in this instance.

  • dochoffiday
    dochoffiday about 12 years
    If I'm viewing the Web Site in VS Express, when I click to view the References, the list is empty (unless I add them manually to the web.config first), and therefore I can't set the "Copy Local" to "true". I think this would work if it were an actual Web Project and not just a simple Web Site in VS.