Crash on mouse over of Cesium map when using asp.net scriptmanager

CantThinkOfAName 20 Reputation points
2025-07-21T17:44:09.4366667+00:00

I have an [asp.net] project using web forms. The aspx page has a Cesium map and crashes when you mouse over it but only if the page also contains the asp:ScriptManager element. If the ScriptManager element is removed, the page does not crash on mouse over on the Cesium map. I created a minimal example where this happens:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestCesium2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head runat="server"> 
    <title></title> 
    <script src="https://cesium.com/downloads/cesiumjs/releases/1.131/Build/Cesium/Cesium.js">
    </script> 
    <link href="https://cesium.com/downloads/cesiumjs/releases/1.131/Build/Cesium/Widgets/widgets.css" rel="stylesheet" /> 
  </head> 
  <body> 
    <form runat="server"> 
      <asp:ScriptManager runat="server" /> 
    </form> 
    <script type="module"> 
      const viewer = new Cesium.Viewer('cesiumContainer', { 
        terrain: Cesium.Terrain.fromWorldTerrain(), 
      }); 
    </script> 
    <div id="cesiumContainer" /> 
  </body> 
</html>

That’s the entire aspx page and there is no code-behind.

When running this, the page loads with the map without error. However, the instant you move the mouse over the map, it crashes on this code on the “if (e) throw e;” line:

String.prototype.startsWith = function String$startsWith(prefix) {
    /// <summary locid="M:J#String.startsWith" />
    /// <param name="prefix" type="String"></param>
    /// <returns type="Boolean"></returns>
    var e = Function._validateParams(arguments, [
        {name: "prefix", type: String}
    ]);
    if (e) throw e;	// <-- EXCEPTION ON THIS LINE
	// Sys.ArgumentTypeException: Sys.ArgumentTypeException: Object of type 'Number' cannot be converted to type 'String'.
	// Parameter name: prefix

    return (this.substr(0, prefix.length) === prefix);
}

Does anyone know how to avoid this crash?

I am using .net framework 4.7.2 and CesiumJS 1.131.

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Raymond Huynh (WICLOUD CORPORATION) 2,215 Reputation points Microsoft External Staff
    2025-07-22T07:08:15.5466667+00:00

    Hello @CantThinkOfAName ,

    This is a classic, tricky issue that happens when you mix older web technologies with modern ones.

    Think of it like this:

    You have two helpers in your project:

    1. ASP.NET's ScriptManager: An older, very formal helper. When you ask it to check if a sentence "starts with" something, it insists that "something" must also be a sentence (a string). It won't accept a number or anything else.
    2. CesiumJS: A newer, more relaxed helper. When it's tracking your mouse, it sometimes needs to check if an ID "starts with" a number (like 123). It assumes it's talking to a modern helper that knows how to treat that number as text for a moment.

    The problem is that the ScriptManager helper is stepping in and overriding the default, relaxed helper. So when Cesium says, "Hey, does this ID start with the number 123?", the ScriptManager helper throws its hands up and says, "Error! You gave me a number, not a sentence!" and everything crashes.

    This is why it only happens when ScriptManager is present and only when you mouse over the map (which is when Cesium's mouse-tracking code runs).

    #Here is how to fix it:

    You need to tell the ScriptManager's helper to either step aside or be less strict. Here are a couple of ways to do that.

    Solution 1: Override the Strict Rule (Recommended)

    You can add a small script to your page that replaces the strict rule with a more forgiving one after ScriptManager loads its code but before Cesium runs.

    Place this script right after your <form> tag:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestCesium2.WebForm1" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
    <title></title> 
    <script src="https://cesium.com/downloads/cesiumjs/releases/1.131/Build/Cesium/Cesium.js">
    </script> 
    <link href="https://cesium.com/downloads/cesiumjs/releases/1.131/Build/Cesium/Widgets/widgets.css" rel="stylesheet" /> 
    </head> 
    <body> 
    <form runat="server"> 
    <asp:ScriptManager runat="server" /> 
    </form>
     
        <!-- FIX: Add this script block to solve the conflict -->
    <script>
          // This checks if a non-native version of startsWith exists and replaces it.
          if (String.prototype.startsWith && String.prototype.startsWith.toString().indexOf('[native code]') === -1) {
            String.prototype.startsWith = function(search, pos) {
              pos = !pos || pos < 0 ? 0 : +pos;
              // This version is more forgiving and works like the browser's built-in function.
              return this.substring(pos, pos + search.length) === search;
            };
          }
    </script>
    <div id="cesiumContainer" style="width: 100%; height: 100vh;"></div>
     
        <script type="module"> 
          const viewer = new Cesium.Viewer('cesiumContainer', { 
            terrain: Cesium.Terrain.fromWorldTerrain(), 
          }); 
    </script> 
    </body> 
    </html>
    

    This new script block effectively tells the page, "Use the modern, flexible startsWith rule," which keeps both ASP.NET and Cesium happy.

    Solution 2: Remove ScriptManager (If You Don't Need It)

    If you aren't using any of the advanced AJAX features of ASP.NET (like UpdatePanel or calling WebMethods from script), the simplest fix is to just delete this line:

    <asp:ScriptManager runat="server" />
    

    If you remove it, the strict helper is never loaded, and the problem goes away.

    Hope this helps you understand not just the "how" but the "why" of the crash!

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.