scriptreference named respond no longer works
Asked Answered
A

7

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?

Ake answered 5/4, 2014 at 18:0 Comment(2)
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: <asp:ScriptManager runat="server"> <Scripts> </Scripts> </asp:ScriptManager>Ake
If you have a reference to <asp:ScriptReference Name="respond" /> in your code (see site.master) then check if you need the Respond polyfill (see: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.Whorish
R
3

In Site.Master file locate the line:

<asp:ScriptReference Name="respond"/>

and modify to:

<asp:ScriptReference Name="respond" Assembly="System.Web.Extensions" />
Reiter answered 11/4, 2014 at 5:58 Comment(2)
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.Ake
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 @ReiterBerte
A
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",
                });
Adelinaadelind answered 4/9, 2014 at 0:39 Comment(0)
S
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);
    }
Steinmetz answered 23/3, 2016 at 10:49 Comment(0)
B
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.

Burstone answered 24/10, 2014 at 7:14 Comment(0)
S
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.

Snooker answered 24/9, 2017 at 2:29 Comment(0)
S
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.

Shatzer answered 4/7, 2016 at 8:58 Comment(0)
H
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

Headwaiter answered 5/2, 2018 at 23:14 Comment(1)
as indicated by another post - can you share information about the post you used? See stackoverflow.com/help/referencingDiminutive

© 2022 - 2024 — McMap. All rights reserved.