Crash on mouse over when using asp.net scriptmanager

I have an asp.net project using web forms.
The aspx page with the Cesium map 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.
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.

Hi @tkt421, welcome to the community!

The error you are seeing is coming from asp.net, not Cesium. Perhaps you could ask the question over there?

The second snippet (not from Cesium) is modifying the prototype of the built-in String prototype. This kind of modification is considered bad practice, partly because it leads to incompatibility with libraries that honor the publicly-documented behavior of the built-in.

In this particular case, the native JavaScript String.prototype.startsWith method is not expected to fail with an argument of type Number.

In case it’s of use to anyone, received a solution here:
Crash on mouse over of Cesium map when using asp.net scriptmanager - Microsoft Q&A

1 Like

@tkt421 thanks for cross-linking that solution! It’s a very helpful answer.