{"record":{"id":"29dcfbbf04636910","repo":"clockworklabs/SpacetimeDB","slug":"while-table-remotetablename-was-applying-del","errorCode":null,"errorMessage":"While table `{RemoteTableName}` was applying:\n{deltaString} \nto:\n{entriesString}","messagePattern":"While table `(.+?)` was applying:\n(.+?) \nto:\n(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sdks/csharp/src/Table.cs","lineNumber":495,"sourceCode":"                    foreach (var row in delta.EventRows)\n                    {\n                        wasInserted.Add(new KeyValuePair<object, Row>(row, row));\n                    }\n                }\n                return;\n            }\n\n            try\n            {\n                Entries.Apply(delta.Delta, wasInserted, wasUpdated, wasRemoved);\n            }\n            catch (Exception e)\n            {\n                var deltaString = parsedTableUpdate.ToString();\n                deltaString = deltaString[..Math.Min(deltaString.Length, 10_000)];\n                var entriesString = Entries.ToString();\n                entriesString = entriesString[..Math.Min(entriesString.Length, 10_000)];\n                throw new Exception($\"While table `{RemoteTableName}` was applying:\\n{deltaString} \\nto:\\n{entriesString}\", e);\n            }\n\n            // Update indices.\n            // This is a local operation -- it only looks at our indices and doesn't invoke user code.\n            // So we don't need to wait for other tables to be updated to do it.\n            // (And we need to do it before any PostApply is called.)\n            // Reminder: We need to loop through the removed entries to delete them prior to inserting the new entries,\n            // in order to avoid keys an error with the same key already added.\n            foreach (var (_, value) in wasRemoved)\n            {\n                OnInternalDeleteHandler.Invoke(value);\n            }\n            foreach (var (_, value) in wasInserted)\n            {\n                OnInternalInsertHandler.Invoke(value);\n            }\n            foreach (var (_, oldValue, newValue) in wasUpdated)\n            {","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/sdks/csharp/src/Table.cs#L477-L513","documentation":"Thrown by the C# client SDK while merging a server subscription delta into the table's local row cache. The inner exception comes from MultiDictionary.Apply (e.g. an 'Attempted to apply ... resulted in a multiplicity of N' failure, meaning the delta assumes different row counts than the client currently holds) or from row deserialization. The message embeds the first 10,000 characters of the incoming delta and of the current cache contents so you can diff what the server sent against local state; the original exception is preserved as InnerException.","triggerScenarios":"Processing a subscription update for this table where the delta's inserts/deletes disagree with the client's cache: overlapping subscriptions on the same table where one is unsubscribed mid-stream, applying updates after a dropped/re-created subscription, or client row types that no longer match the redeployed module schema (added/removed columns).","commonSituations":"Module redeployed (schema changed) while the client keeps bindings generated by the old CLI; toggling subscriptions on the same table at runtime; reconnecting after a server restart with stale local cache rows; SDK NuGet package version drifted from the spacetimedb server version.","solutions":["Inspect the InnerException and the dumped delta vs entries strings to identify which table row key/multiplicity disagrees.","Regenerate C# bindings (spacetime generate) against the currently deployed module and align the SpacetimeDB SDK NuGet version with the server version.","Ensure only one active subscription covers a given table at a time: unsubscribe fully before re-subscribing to the same table.","If the cache is corrupt, recreate the DbConnection/DbView so the cache is rebuilt from a fresh SubscriptionApplied snapshot."],"exampleFix":"// before: overlapping subscriptions on the same table\nvar sub1 = conn.Db.Player.OnInsert(p => ...);\nvar subs = conn.SubscriptionBuilder()\n    .OnApplied(() => ...)\n    .Subscribe(\"SELECT * FROM Player\");\n// ...later another .Subscribe(\"SELECT * FROM Player\") while cache is mid-update\n\n// after: one subscription per table, unsubscribe before changing scope\nawait subs.UnsubscribeAsync();\nvar subs2 = conn.SubscriptionBuilder()\n    .OnError(e => Log.Error($\"apply failed: {e.InnerException?.Message}\"))\n    .Subscribe(\"SELECT * FROM Player\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"conn.SubscriptionBuilder()\n    .OnError(ex => {\n        var root = ex.InnerException ?? ex;\n        Log.Error($\"Table apply failed: {root.Message}\"); // message contains delta/cache dump\n        // recover: unsubscribe and resubscribe to rebuild the cache\n    })\n    .Subscribe(\"SELECT * FROM Player\");","preventionTips":["Regenerate C# bindings after every module schema change and keep the SDK NuGet version aligned with the server.","Maintain at most one active subscription per table; fully unsubscribe before re-subscribing with a different query.","Never hand-edit generated table classes."],"tags":["csharp","sdk","subscription","cache-inconsistency","schema-mismatch"],"backgroundTag":"client-cache-out-of-sync","analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}