{"record":{"id":"c73dc31e81ff5aeb","repo":"dotnet/wpf","slug":"sr-filemanagementstreamproxyisreadonly","errorCode":null,"errorMessage":"SR.FileManagementStreamProxyIsReadOnly","messagePattern":"SR\\.FileManagementStreamProxyIsReadOnly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamProxy.cs","lineNumber":260,"sourceCode":"    #endregion Object Overrides\n\n    #region Internal Properties\n    //--------------------------------------------------------------------------\n    // Internal Properties\n    //--------------------------------------------------------------------------\n\n    internal Stream Target\n    {\n        get { return _proxy; }\n\n        set {\n            if (!_isTargetReadOnly)\n            {\n                _proxy = value;\n            }\n            else\n            {\n                throw new InvalidOperationException(\n                    SR.FileManagementStreamProxyIsReadOnly);\n            }\n        }\n    }\n        #endregion Internal Properties\n\n        #region Private Fields\n        //--------------------------------------------------------------------------\n        // Private Fields\n        //--------------------------------------------------------------------------\n\n        private Stream _proxy;\n        private bool _isTargetReadOnly;\n\n    #endregion Private Fields\n}\n}\n","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/StreamProxy.cs#L242-L278","documentation":"StreamProxy's internal proxy property setter refuses to change the target stream when the proxy was created over a read-only target (_isTargetReadOnly). It throws InvalidOperationException(SR.FileManagementStreamProxyIsReadOnly).","triggerScenarios":"Assigning the Proxy property (internally, during stream management) on a StreamProxy constructed over a read-only file or stream.","commonSituations":"Document opened read-only (file locked by another process or opened with FileAccess.Read) while the document manager attempts to swap or retarget the underlying stream.","solutions":["Open the underlying file with FileAccess.ReadWrite so the proxy is not flagged read-only","Ensure the file is not locked read-only by another process or by file attributes","Avoid retargeting proxies over read-only streams; create a new writable proxy instead","Catch InvalidOperationException and fall back to read-only document mode"],"exampleFix":"// before\nvar stream = File.OpenRead(path); // read-only target\nvar proxy = new StreamProxy(stream, isTargetReadOnly: true);\n// after\nvar stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite);\nvar proxy = new StreamProxy(stream, isTargetReadOnly: false);","handlingStrategy":"validation","validationCode":"if (proxy.IsTargetReadOnly) { /* do not retarget; open a writable copy */ }","typeGuard":null,"tryCatchPattern":"try { proxy.Proxy = newStream; } catch (InvalidOperationException) { /* handle read-only proxy */ }","preventionTips":["Open backing files with FileAccess.ReadWrite when editing is expected","Check for file locks (sharing violations) before opening","Never retarget proxies built over read-only targets"],"tags":["wpf","stream-proxy","read-only","file-access"],"backgroundTag":"permission-denied","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}