dotnet/wpf · error · ArgumentException
SR.Effect_SourceUriMustBeFileOrPack
Error message
SR.Effect_SourceUriMustBeFileOrPack
What it means
PixelShader.UriSource was set to a URI that is neither a file: URI nor a pack: URI, and UriSourcePropertyChangedHook rejected it with ArgumentException(SR.Effect_SourceUriMustBeFileOrPack). The loader only supports reading shader bytecode from the file system or from a WPF pack URI.
Solutions
- Copy the shader to a local file (or embed it as a pack Resource/Content) and reference it via file:/pack: URI
- Download the remote shader to disk first, then set UriSource to the local path
- Use SetStreamSource(Stream) with the byte stream instead of UriSource
- Validate the URI scheme before assignment: uri.IsFile || PackUriHelper.IsPackUri(uri)
Example fix
// before
shader.UriSource = new Uri("https://cdn.example.com/shader.ps", UriKind.Absolute); // throws
// after
File.WriteAllText(localPath, downloadedShader); // or ship as pack resource
shader.UriSource = new Uri(localPath, UriKind.Absolute); // file: URI Defensive patterns
Strategy: validation
Validate before calling
static void ValidateShaderUri(Uri uri)
{
if (uri == null) throw new ArgumentNullException(nameof(uri));
bool ok = uri.IsFile || MS.Internal.IO.Packaging.PackUriHelper.IsPackUri(uri);
if (!ok) throw new ArgumentException("PixelShader.UriSource must be a file or pack URI", nameof(uri));
} Try / catch
try { shader.UriSource = uri; }
catch (ArgumentException ex) when (ex.Message.Contains("file or pack"))
{
// copy resource locally or use SetStreamSource instead
} Prevention
- Ship shaders as pack Resource/Content or local files
- Never point UriSource at http/https/custom-scheme URIs
- For remote shaders, download to disk or use SetStreamSource
- Validate URI scheme in configuration before assignment
When it happens
Trigger: Assigning pixelShader.UriSource = new Uri("http://...") or any scheme other than file/pack; URIs built from user config with remote or custom schemes.
Common situations: Downloading shaders from a web server and pointing UriSource at the http URL; relative URIs that resolve to unsupported schemes; app settings storing remote shader URLs.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- SR.AbsoluteUriOnly
- SR.Format(SR.ArgumentPropertyMustNotBeNull, "uriRemote"…
- SR.NonPackSooAbsoluteUriNotAllowed
- SR.UriNotAbsolute
- UriMustBeAbsolute
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1290143ad29a6e3e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/PixelShader.cs:90
try {
if (newUri != null)
{
if (!newUri.IsAbsoluteUri)
{
newUri = BaseUriHelper.GetResolvedUri(BaseUriHelper.BaseUri, newUri);
}
Debug.Assert(newUri.IsAbsoluteUri);
// Now the URI is an absolute URI.
//
// Only allow file and pack URIs.
if (!newUri.IsFile &&
!MS.Internal.IO.Packaging.PackUriHelper.IsPackUri(newUri))
{
throw new ArgumentException(SR.Effect_SourceUriMustBeFileOrPack);
}
// Security: When loading XPS content, block shader URIs that
// escape the current package to prevent SSRF.
if (!XpsLoadingContext.IsUriAllowedInCurrentContext(newUri))
{
throw new FileFormatException(SR.Resource_XpsPackageBoundaryViolation);
}
stream = WpfWebRequestHelper.CreateRequestAndGetResponseStream(newUri);
}
LoadPixelShaderFromStreamIntoMemory(stream);
}
finally
{
stream?.Dispose();
}View on GitHub (pinned to 81131a70a4)