JavaScript runtime error for Microsoft AJAX scripts

孤街醉人 提交于 2019-12-12 05:06:31

问题


I have an ASP.NET web forms project in VS.NET 2012 that has been running great for weeks. All of the sudden out of nowhere I'm getting the following everytime I begin to debug the project:

Unhandled exception at line 1, column 12302 in http:// localhost :1449/bundles/MsAjaxJs?v=_Onj24X0Yu7cK2nh78YBmVwMlQTGcakS5HZSOI_a6SM1

0x800a139e - JavaScript runtime error: Sys.InvalidOperationException: The script 'Timer.js' has been referenced multiple times. If referencing Microsoft AJAX scripts explicitly, set the MicrosoftAjaxMode property of the ScriptManager to Explicit.

(note: added spaces in error message to word 'localhost' because these URLs are not formed well for posting; link is irrelevant anyway)

This is odd because it just began to occur out of nowhere. I did some searching on this and came up with anything that would make it work.

In the auto-generated BundleConfig.cs, this file is only listed 1x:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(
          "~/Scripts/WebForms/WebForms.js",
          "~/Scripts/WebForms/WebUIValidation.js",
          "~/Scripts/WebForms/MenuStandards.js",
          "~/Scripts/WebForms/Focus.js",
          "~/Scripts/WebForms/GridView.js",
          "~/Scripts/WebForms/DetailsView.js",
          "~/Scripts/WebForms/TreeView.js",
          "~/Scripts/WebForms/WebParts.js"));

    bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
        "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

    // Use the Development version of Modernizr to develop with and learn from. Then, when you’re
    // ready for production, use the build tool at http://modernizr.com to pick only the tests you need
    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
        "~/Scripts/modernizr-*"));
}

In the web.config there is no duplicate or listing otherwise for the timer. I did a search on the project and this was the only place it was listed.

I also made sure all of the NuGet packages where up to date. Anyone understand or know what has caused this error, and how can I fix it?


回答1:


Solved this issue. I have got to believe one of the NuGet package updates I downloaded was registering these files separately, and at the same time must have been new logic. I say this because this issue started out of nowhere.

The solution was simply to comment out or remove the offending scripts that were being registered more than 1x in the BundleConfig.cs file. Here is the modified section of script registration:

bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
         "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
         "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js"));

The following (2) scripts were the culprit:

"~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
"~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"

After removing them the error went away, the functionality within those scripts still works (I use Ajax timers), and the error went away.



来源:https://stackoverflow.com/questions/19103128/javascript-runtime-error-for-microsoft-ajax-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!