{"record":{"id":"f6749f980ce8d8ab","repo":"stride3d/stride","slug":"argumentnullexception-value","errorCode":null,"errorMessage":"ArgumentNullException: value","messagePattern":"ArgumentNullException: value","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/ScriptSourceFileAssetViewModel.cs","lineNumber":481,"sourceCode":"\n            public ScriptTextAccessor(ScriptSourceFileAssetViewModel asset)\n            {\n                this.asset = asset;\n            }\n\n            [NotNull]\n            public string Get()\n            {\n                // Retrieve text from the editor thread\n                lock (asset.mirroredText)\n                {\n                    return asset.mirroredText.ToString();\n                }\n            }\n\n            public void Set([NotNull] string value)\n            {\n                if (value == null) throw new ArgumentNullException(nameof(value));\n\n                // Set text on the editor thread\n                if (asset.Dispatcher.CheckAccess())\n                    asset.TextDocument.Text = value;\n                else\n                    asset.Dispatcher.InvokeAsync(() => asset.TextDocument.Text = value).Wait();\n            }\n\n            public async Task Save(Stream stream)\n            {\n                await asset.Session.Dispatcher.InvokeTask(async () =>\n                {\n                    using (var streamWriter = new StreamWriter(stream, Encoding.UTF8, 1024, true))\n                    {\n                        await streamWriter.WriteAsync(Get());\n                    }\n                });\n            }","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/ScriptSourceFileAssetViewModel.cs#L463-L499","documentation":"ScriptSourceFileAssetViewModel.TextValue.Set is a WPF value accessor that pushes edited script text back to the asset's TextDocument. It explicitly rejects a null value with ArgumentNullException(nameof(value)). The library throws this because null is not a meaningful script source; callers must always supply a string (empty string is accepted for a blank script).","triggerScenarios":"Calling Set(null) on the TextValue accessor exposed by ScriptSourceFileAssetViewModel, e.g. a WPF binding or view code pushing a null string from a control into the asset view model's mirrored text setter.","commonSituations":"A two-way WPF TextBox binding whose source property resolves to null (e.g. File.ReadAllText returned null after a failed load, or a deserializer produced a null script field); view-model code copying asset.TextDocument before the document is initialized and writing it back.","solutions":["Find the caller producing the null string and coalesce it to an empty string before calling Set.","If a WPF binding feeds this setter, add a fallback/TargetNullValue='' in the binding or a converter that maps null to string.Empty.","Ensure the underlying asset's script text is loaded/initialized before any editor interaction can write it back."],"exampleFix":"// before\nviewModel.TextValue.Set(loadedScript); // loadedScript may be null\n// after\nviewModel.TextValue.Set(loadedScript ?? string.Empty);","handlingStrategy":"validation","validationCode":"if (text == null) text = string.Empty;\nviewModel.TextValue.Set(text);","typeGuard":"bool IsUsableText(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":null,"preventionTips":["Coalesce nulls to string.Empty at every boundary that feeds editor bindings.","Use Binding FallbackValue/TargetNullValue in XAML for script text properties.","Never persist null for script source fields; serialize empty strings instead."],"tags":["null-reference","wpf","asset-editor","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}