{"record":{"id":"bdfa02ceb24dd013","repo":"dotnet/wpf","slug":"sr-format-sr-bamlisnotsupportedoutsideofapplicationresources","errorCode":null,"errorMessage":"SR.Format(SR.BamlIsNotSupportedOutsideOfApplicationResources)","messagePattern":"SR\\.Format\\(SR\\.BamlIsNotSupportedOutsideOfApplicationResources\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs","lineNumber":37,"sourceCode":"{\n    // !!!! Note: Those methods are registered as MimeObjectFactory.StreamToObjectFactoryDelegate. The caller expects the \n    // delgate to close stream. \n    internal static class AppModelKnownContentFactory\n    {\n        // <summary>\n        // Creates an object instance from a Baml stream and it's Uri\n        // </summary>\n        internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)\n        {\n            return BamlConverterCore(stream, baseUri, canUseTopLevelBrowser, sandboxExternalContent, allowAsync, isJournalNavigation, out asyncObjectConverter, false);\n        }\n\n        internal static object BamlConverterCore(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter, bool isUnsafe)\n        {\n            asyncObjectConverter = null;\n            if (isUnsafe)\n            {\n                throw new InvalidOperationException(SR.Format(SR.BamlIsNotSupportedOutsideOfApplicationResources));\n            }\n            // If this stream comes from outside the application throw\n            //\n            if (!BaseUriHelper.IsPackApplicationUri(baseUri))\n            {\n                throw new InvalidOperationException(SR.BamlIsNotSupportedOutsideOfApplicationResources);\n            }\n\n            // If this stream comes from a content file also throw\n            Uri partUri = PackUriHelper.GetPartUri(baseUri);\n            string partName, assemblyName, assemblyVersion, assemblyKey;\n            BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey);\n            if (ContentFileHelper.IsContentFile(partName))\n            {\n                throw new InvalidOperationException(SR.BamlIsNotSupportedOutsideOfApplicationResources);\n            }\n\n            ParserContext pc = new ParserContext","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs#L19-L55","documentation":"AppModelKnownContentFactory.BamlConverterCore refuses to load BAML when isUnsafe is true, throwing InvalidOperationException with SR.BamlIsNotSupportedOutsideOfApplicationResources. BAML may only be consumed from trusted application resources; partial-trust ('unsafe') contexts are explicitly blocked. This is a deliberate security boundary of the WPF application model, not an internal bug.","triggerScenarios":"Navigating (e.g. NavigationWindow/Frame, Application.LoadComponent path) to a BAML resource while running in a partial-trust/sandboxed context that flags the load as unsafe.","commonSituations":"XBAP or partial-trust ClickOnce deployments attempting to load compiled BAML pages; browser-hosted WPF navigating to internal resource URIs under security restrictions.","solutions":["Run the application with full trust (adjust ClickOnce/XBAP permission set) so the BAML load is not flagged unsafe.","Ship the content as loose XAML or a compiled assembly loaded through a supported mechanism instead of BAML in this context.","Restructure navigation so BAML pages are only loaded from application resources in a fully trusted app domain."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { NavigateTo(bamlUri); }\ncatch (InvalidOperationException) { /* fall back to loose XAML via XamlReader */ }","preventionTips":["Only rely on BAML loading in full-trust desktop WPF applications.","Do not use BAML in XBAP/partial-trust deployments; use loose XAML instead.","Audit deployment trust settings before shipping resource-based navigation."],"tags":["wpf","baml","security","partial-trust"],"backgroundTag":"operation-not-supported","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"}