dotnet/wpf · error
SR.ParserProvideValueCantSetUri
Error message
SR.ParserProvideValueCantSetUri
What it means
When a markup extension's ProvideValue runs, the service provider exposes IUriContext, but its BaseUri setter deliberately throws NotSupportedException: markup extensions must not set the BaseUri during ProvideValue; only the parser owns it. The getter returns the context's BaseUri.
Solutions
- Do not set BaseUri inside ProvideValue; read it and resolve your URI against it instead
- Compute absolute URIs by combining the read-only BaseUri with your relative path
- Store desired state in the markup extension's constructor/properties rather than mutating services
Example fix
// before
var uriContext = (IUriContext)serviceProvider.GetService(typeof(IUriContext));
uriContext.BaseUri = new Uri("pack://application:,,,/MyAssembly");
// after
var uriContext = (IUriContext)serviceProvider.GetService(typeof(IUriContext));
var resolved = new Uri(uriContext.BaseUri, relativePath); // read-only, combine instead of assigning Defensive patterns
Strategy: try-catch
Validate before calling
var uriCtx = serviceProvider.GetService(typeof(IUriContext)) as IUriContext; // never assign uriCtx.BaseUri inside ProvideValue
Try / catch
try { ProvideValueCore(sp); }
catch (NotSupportedException ex) when (ex.Message.Contains("BaseUri")) { /* stop mutating BaseUri; read instead */ } Prevention
- Treat services obtained from IServiceProvider as read-only
- Resolve relative URIs against BaseUri rather than overwriting it
- Never persist mutated service state inside markup extensions
When it happens
Trigger: Inside a custom MarkupExtension.ProvideValue implementation, casting IServiceProvider.GetService(typeof(IUriContext)) to IUriContext and assigning to BaseUri, or code that mutates BaseUri while the parser is invoking ProvideValue.
Common situations: Custom markup extensions that try to resolve relative URIs by rewriting BaseUri during ProvideValue; code migrated from a static-resource context where BaseUri appeared writable.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- NotSupportedException
- IAmbientProvider
- IXamlSchemaContextProvider
- SR.ColorConvertedBitmapExtensionNoSourceImage
- SR.ColorConvertedBitmapExtensionNoSourceProfile
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5e82b367a83aee61.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/ProvideValueServiceProvider.cs:72
}
// IProvideValueTarget implementation
object IProvideValueTarget.TargetObject
{
get { return _targetObject; }
}
object IProvideValueTarget.TargetProperty
{
get { return _targetProperty; }
}
// IUriContext implementation
Uri IUriContext.BaseUri
{
get { return _context.BaseUri; }
set { throw new NotSupportedException(SR.ParserProvideValueCantSetUri); }
}
bool IFreezeFreezables.FreezeFreezables
{
get
{
return _context.FreezeFreezables;
}
}
bool IFreezeFreezables.TryFreeze(string value, Freezable freezable)
{
return _context.TryCacheFreezable(value, freezable);
}
Freezable IFreezeFreezables.TryGetFreezable(string value)
{
return _context.TryGetFreezable(value);View on GitHub (pinned to 81131a70a4)