Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 544
dochoffiday Avatar asked Apr 26 '12 21:04

dochoffiday


3 Answers

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

like image 85
dknaack Avatar answered Nov 11 '22 12:11

dknaack


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.

like image 1
Joe Enzminger Avatar answered Nov 11 '22 13:11

Joe Enzminger


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.

like image 1
Charles Lambert Avatar answered Nov 11 '22 12:11

Charles Lambert