dotnet/wpf · error · InvalidOperationException

SchemaInvalidForTransport

Error message

SchemaInvalidForTransport

What it means

PackWebRequest.GetResponse must return a real WebRequest, but for pack URIs that are fully resolvable in-process (the whole URI lives inside the pack scheme, e.g. application:///... with no container part), the request object is only a PseudoWebRequest. Since PseudoWebRequest cannot be handed to external code, GetResponse throws InvalidOperationException with SR.SchemaInvalidForTransport. This enforces that only transportable (real network-backed) requests escape the pack layer.

Solutions

  1. Resolve pack://application:/// resources through Application resource APIs (Application.LoadComponent, Application.GetResourceStream) instead of GetResponse.
  2. Only call GetResponse on pack URIs with a real outer transport (e.g. pack://http:,...).
  3. Inspect InnerResponse / use GetRequest(false) checks to detect PseudoWebRequest before calling GetResponse and fall back to resource APIs.

Example fix

// before
var req = (PackWebRequest)WebRequest.Create(new Uri("pack://application:,,,/page.xaml"));
var resp = req.GetResponse();
// after
var s = Application.GetResourceStream(new Uri("page.xaml", UriKind.Relative));
Defensive patterns

Strategy: type-guard

Validate before calling

if (req is PackWebRequest pwr && pwr.InnerResponse is PseudoWebRequest)
    // use Application.GetResourceStream / LoadComponent instead

Type guard

static bool IsTransportable(PackWebRequest r) => !(r.InnerResponse is PseudoWebRequest) && r.InnerResponse != null;

Try / catch

try { return req.GetResponse(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("transport")) { return null; /* resolve via Application resource APIs */ }

Prevention

When it happens

Trigger: Calling PackWebRequest.GetResponse (or exposing InnerResponse) for a pack URI that resolves to a PseudoWebRequest — i.e. a URI without a valid outer http:/file: transport component or a pack URI that is handled entirely in-memory.

Common situations: Reflection-based or generic WebRequest pipelines that call GetResponse() on WebRequest.Create("pack://application:,,,/page.xaml") style URIs; code that assumes every WebRequest supports real transport.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/a53064e9a6adeeaf. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackWebRequest.cs:164

            }
            
            if (cachedPackageAvailable)
            {
#if DEBUG
                if (PackWebRequestFactory._traceSwitch.Enabled)
                    System.Diagnostics.Trace.TraceInformation(
                        DateTime.Now.ToLongTimeString() + " " + DateTime.Now.Millisecond + " " +
                        Environment.CurrentManagedThreadId + ": " + 
                        "PackWebRequest - Getting response from Package Cache");
#endif
                return new PackWebResponse(_uri, _innerUri, _partName, _cacheEntry, _cachedPackageIsThreadSafe);
            }
            else
            {
                // only return a real WebRequest instance - throw on a PseudoWebRequest
                WebRequest request = GetRequest(false);
                if (_webRequest == null || _webRequest is PseudoWebRequest)
                    throw new InvalidOperationException(SR.SchemaInvalidForTransport);

#if DEBUG
                if (PackWebRequestFactory._traceSwitch.Enabled)
                    System.Diagnostics.Trace.TraceInformation(
                        DateTime.Now.ToLongTimeString() + " " + DateTime.Now.Millisecond + " " +
                        Environment.CurrentManagedThreadId + ": " + 
                        "PackWebRequest - Getting new response");
#endif
                // Create a new response for every call
                return new PackWebResponse(_uri, _innerUri, _partName, request);
            }
        }
        #endregion

        //------------------------------------------------------
        //
        //  Public Properties
        //

View on GitHub (pinned to 81131a70a4)