dotnet/maui · error · NotSupportedException
The streams can't be read for comparison
Error message
The streams can't be read for comparison
What it means
The AreStreamsEqual utility compares two streams byte-for-byte but first checks that both CanRead. If either stream cannot be read, it throws NotSupportedException because the comparison is impossible. This is a precondition guard, not a recoverable runtime fault.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Utilities.cs:166
return (short)(i & 0xFFFF);
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public static bool AreStreamsEqual(Stream left, Stream right)
{
if (null == left)
{
return right == null;
}
if (null == right)
{
return false;
}
if (!left.CanRead || !right.CanRead)
{
throw new NotSupportedException("The streams can't be read for comparison");
}
if (left.Length != right.Length)
{
return false;
}
var length = (int)left.Length;
// seek to beginning
left.Position = 0;
right.Position = 0;
// total bytes read
int totalReadLeft = 0;
int totalReadRight = 0;
// bytes read on this iterationView on GitHub (pinned to f377ff1c5e)
Solutions
- Verify left.CanRead && right.CanRead before calling AreStreamsEqual.
- Open file streams with FileAccess.Read or ReadWrite when they will be compared.
- If comparing data, copy both streams into MemoryStreams first if read access is uncertain.
Example fix
// before
bool same = Utilities.AreStreamsEqual(left, right);
// after
if (!left.CanRead || !right.CanRead)
{
throw new InvalidOperationException("Both streams must be readable for comparison.");
}
bool same = Utilities.AreStreamsEqual(left, right); Defensive patterns
Strategy: validation
Validate before calling
// Before comparing streams
if (left == null || right == null)
{
// null comparison is valid in AreStreamsEqual (null == null is true)
}
if (left != null && right != null && (!left.CanRead || !right.CanRead))
{
throw new InvalidOperationException("Both streams must be readable for comparison.");
}
bool equal = Utilities.AreStreamsEqual(left, right); Prevention
- Open FileStreams with at least read access when they will be compared.
- Do not compare disposed streams — CanRead may return false after Close.
- Copy untrusted streams into MemoryStreams before comparison if readability is uncertain.
When it happens
Trigger: Calling Utilities.AreStreamsEqual(left, right) where left.CanRead or right.CanRead is false — e.g. passing a write-only FileStream or a closed stream whose CanRead has become false.
Common situations: Comparing a stream that was opened with write-only access; passing a stream that was already disposed (some implementations report CanRead=false after Close); comparing against a network stream whose read side has been shut down.
Related errors
- The stream doesn't support modifications.
- Bad value for origin
- Invalid enumeration value
- No file exists at "{0}"
- Unexpected platform (expected: android) in device: {deviceDe
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/384f9dd9fb81918e.
Report an issue: GitHub.