{"record":{"id":"27fdef3c67e76ee1","repo":"dotnet/wpf","slug":"sr-bamlisnotsupportedoutsideofapplicationresources","errorCode":null,"errorMessage":"SR.BamlIsNotSupportedOutsideOfApplicationResources","messagePattern":"SR\\.BamlIsNotSupportedOutsideOfApplicationResources","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs","lineNumber":43,"sourceCode":"        // 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\n            {\n                BaseUri = baseUri,\n                SkipJournaledProperties = isJournalNavigation\n            };\n\n            return Application.LoadBamlStreamWithSyncInfo(stream, pc);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs#L25-L61","documentation":"BamlConverterCore throws SR.BamlIsNotSupportedOutsideOfApplicationResources when the baseUri of the stream is not a pack-application URI (BaseUriHelper.IsPackApplicationUri fails). BAML streams must originate from application resources (pack://application:,,,); BAML from arbitrary external URIs is rejected because compiled BAML is only meaningful/trusted within the application's own resources.","triggerScenarios":"BamlConverter invoked with a baseUri such as an http(s) URL, a site-of-origin pack URI, or a file path rather than a pack application URI.","commonSituations":"Pointing Frame/NavigationService at a .baml on disk or a remote server; misconfigured source URIs after moving a resource from the application assembly to loose content.","solutions":["Reference the BAML via a pack application URI, e.g. new Uri(\"pack://application:,,,/MyAssembly;component/Page.xaml\").","Ensure the resource is embedded as Page/Resource build action in the application assembly rather than Content or an external file.","If the content is external, ship XAML instead of BAML since external BAML is unsupported."],"exampleFix":"// before\nframe.Source = new Uri(\"file:///C:/app/Page.baml\");\n// after\nframe.Source = new Uri(\"pack://application:,,,/MyApp;component/Page.xaml\");","handlingStrategy":"validation","validationCode":"if (!BaseUriHelper.IsPackApplicationUri(uri))\n    throw new ArgumentException(\"BAML can only be loaded from a pack application URI\");","typeGuard":null,"tryCatchPattern":"try { LoadBaml(uri); }\ncatch (InvalidOperationException) { /* convert content to XAML or fix the URI */ }","preventionTips":["Always reference compiled XAML via pack://application:,,,/Assembly;component/... URIs.","Keep navigable XAML as Page build action inside the application assembly.","Never point Frame/NavigationService at external .baml files or remote URLs."],"tags":["wpf","baml","pack-uri","resources"],"backgroundTag":"invalid-url","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"}