C# – n explanation behind the error “The type or namespace name ‘Script’ does not exist in the namespace ‘System.Web'”

asp.netcdeploymentiis-7

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.

Best Answer

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