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:
- 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. - 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!