6

Using: Visual Studio Express 2013 for Web to write a .NET 4.5.1 site.

Project initially built on the default "Create New Website" template therefore the parts in question were added to my project by the IDE and have not been edited.

This has been a several weeks long project and today I began receiving an error out of the blue in relation to "canned" items added at create time. It has been working without error until now.

The error message is:

Server Error in '/' Application.  

'respond' is not a valid script name.  The name must end in '.js'.

I have debugged this to be directly related to this line in my site.master file:

<asp:ScriptReference Name="respond" />

SEE COMMENT HERE This reference is contained in the section of my master file:

This is part of the much larger group of scriptreferences added by the IDE at create time.

In troubleshooting I have tried adding the .js; add a path attribute to the actual file; and commented out the line entirely.

Adding the extension and/or the path results in a different error:

Server Error in '/' Application.

The assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' does not contain a Web resource that
has the name 'respond.js'. Make sure that the resource name is spelled correctly.

The only successful troubleshooting has been commenting it out BUT this breaks another key feature: Accessing my links requires the .ASPX extension now as previously I could access my links without specifying the extension on my file... and this is the default way the project was created via the ide, so with this fix in place, none of my links work without editing each and every one to include and extension. NOT IDEAL.

I've tried using the Package Manager to update and nothing has been successful there. I have also verified the respond.js file exists in my scripts folder as do the others like bootstrap.

I have searched here and googled for quite some time but there are so many unrelated results that contain excerpts from the scriptmanager that the results are endless.

I am unsure of the correction needed for this or if other files are required. Rebuilding my site has no effect, I've removed "temp" files per one post I read that said it might work for a different but similar issue.

What is the corrective action for this error?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Adam Wood
  • 289
  • 2
  • 4
  • 13
  • Just a note: This page is not including some of my text. Even when I edit it, it shows my content but viewing it hides it for some reason. It should read: This reference is contained in the section of my master file: – Adam Wood Apr 05 '14 at 18:02
  • If you have a reference to in your code (see site.master) then check if you need the Respond polyfill (see:https://github.com/scottjehl/Respond) which can be added using NuGet and includes respond.js under /scripts. Then see Aaron0's answer and add a definition to the script bundler. – Anthony Jul 14 '21 at 12:51

7 Answers7

3

In Site.Master file locate the line:

<asp:ScriptReference Name="respond"/>

and modify to:

<asp:ScriptReference Name="respond" Assembly="System.Web.Extensions" />
sam
  • 31
  • 1
  • Thanks for the reply, this only results in the same message as before: "'respond' is not a valid script name. The name must end in '.js'." and adding the .js has the same effect as in the original post. – Adam Wood Apr 11 '14 at 20:59
  • If it works in the development environment but in production (a different machine) try to force copy the reference, in the BIN directory Project -> Reference -> Copy Local: True In addition to adding the reference that indicates @sam – mainmind83 Jun 21 '21 at 12:29
2

I ran into this same issue myself and fixed it by doing the following.

Add the following code to the RegisterBundles method of the BundleConfig class:

ScriptManager.ScriptResourceMapping.AddDefinition(
                "respond",
                new ScriptResourceDefinition
                {
                    Path = "~/Scripts/respond.min.js",
                    DebugPath = "~/Scripts/respond.js",
                });
Aaron0
  • 389
  • 4
  • 14
2

I had the same problem, and none of the above worked... Verify your global.asax.cs, the Routeconfig and BundleConfig lines were missing in my case, after adding them, it worked again.

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
snookie
  • 31
  • 3
1

Solution:

  • Compile the project at the production server, instead of precompiling on at development machine.

  • If using VS one click publishing tool, under "Settings", make sure "Precompile during publishing" is unchecked.

Community
  • 1
  • 1
Ric Gui
  • 11
  • 2
1

This problem occurred for me when I deployed a template asp.net web forms application generated from Visual Studio (2015 in my case) to Azure app service.

For me, none of the solutions given above worked. I got the errors exactly as described in this question.

Then I chanced upon the following article that shows an example of adding a jquery bundle. Adding Bundling and Minification to Web Forms

Following that example, I removed the template code for AddDefinition for "respond" in RegisterBundles method. Then I added the following and rebuilt and uploaded the application dll.

            bundles.Add(new ScriptBundle("~/bundles/respond").Include(
                    "~/Scripts/respond.min.js"));

Then I added the following to Asp:PlaceHolder in site.master.

        <%: Scripts.Render("~/bundles/respond") %>

Finally, I removed the inclusion of respond in ScriptManager in site.master.

user173399
  • 464
  • 5
  • 21
0

It seems your bundleConfig isn't starting up.

Try to rebuild and clean the project first. After that, try to look into the file Global.asax.cs and see if there is something wrong.

Or try to get a default Global.asax.cs file and copy it into it.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
0

I tried the above methods without much success. Then I tried as indicated by another post

<add name="BundleModule" type="System.Web.Optimization.BundleModule" />

in between and in web.config

works like a charm. Graham https://forums.asp.net/t/1857743.aspx?Bundling+not+working+when+deployed+to+web+host+works+fine+locally

Graham
  • 1
  • 1
  • *as indicated by another post* - can you share information about the post you used? See https://stackoverflow.com/help/referencing – dbc Feb 05 '18 at 23:21