dotnet/wpf · error · InvalidOperationException
SR.BamlIsNotSupportedOutsideOfApplicationResources
Error message
SR.BamlIsNotSupportedOutsideOfApplicationResources
What it means
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.
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.
Example fix
// before
frame.Source = new Uri("file:///C:/app/Page.baml");
// after
frame.Source = new Uri("pack://application:,,,/MyApp;component/Page.xaml"); Defensive patterns
Strategy: validation
Validate before calling
if (!BaseUriHelper.IsPackApplicationUri(uri))
throw new ArgumentException("BAML can only be loaded from a pack application URI"); Try / catch
try { LoadBaml(uri); }
catch (InvalidOperationException) { /* convert content to XAML or fix the URI */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- SR.EntryAssemblyIsNull
- SR.NonPackAppAbsoluteUriNotAllowed
- Can't Assign to Known Type attributes
- Could not find prefix for type
- Found unexpected Xmlns BAML record
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/27fdef3c67e76ee1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppModelKnownContentFactory.cs:43
// Creates an object instance from a Baml stream and it's Uri
// </summary>
internal static object BamlConverter(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter)
{
return BamlConverterCore(stream, baseUri, canUseTopLevelBrowser, sandboxExternalContent, allowAsync, isJournalNavigation, out asyncObjectConverter, false);
}
internal static object BamlConverterCore(Stream stream, Uri baseUri, bool canUseTopLevelBrowser, bool sandboxExternalContent, bool allowAsync, bool isJournalNavigation, out XamlReader asyncObjectConverter, bool isUnsafe)
{
asyncObjectConverter = null;
if (isUnsafe)
{
throw new InvalidOperationException(SR.Format(SR.BamlIsNotSupportedOutsideOfApplicationResources));
}
// If this stream comes from outside the application throw
//
if (!BaseUriHelper.IsPackApplicationUri(baseUri))
{
throw new InvalidOperationException(SR.BamlIsNotSupportedOutsideOfApplicationResources);
}
// If this stream comes from a content file also throw
Uri partUri = PackUriHelper.GetPartUri(baseUri);
string partName, assemblyName, assemblyVersion, assemblyKey;
BaseUriHelper.GetAssemblyNameAndPart(partUri, out partName, out assemblyName, out assemblyVersion, out assemblyKey);
if (ContentFileHelper.IsContentFile(partName))
{
throw new InvalidOperationException(SR.BamlIsNotSupportedOutsideOfApplicationResources);
}
ParserContext pc = new ParserContext
{
BaseUri = baseUri,
SkipJournaledProperties = isJournalNavigation
};
return Application.LoadBamlStreamWithSyncInfo(stream, pc);View on GitHub (pinned to 81131a70a4)