runtime: System.Net.Tests.HttpRequestStreamTests.CanWrite_Get_ReturnsFalse and CanRead_Get_ReturnsFalse fails on UAPAOT: NotSupported_UnwritableStream/NotSupported_UnreadableStream

System.Net.Tests.HttpRequestStreamTests.CanWrite_Get_ReturnsFalse [FAIL]
        Assert.Throws() Failure
        Expected: typeof(System.InvalidOperationException)
        Actual:   typeof(System.NotSupportedException): NotSupported_UnwritableStream. For more information, visit http://go.microsoft.com/fwlink/?Lin
  kId=623485
        Stack Trace:
              at xunit.console.netcore!<BaseAddress>+0xa35f68
              at System.Net.Tests.HttpRequestStreamTests.<>c__DisplayClass16_0.<CanWrite_Get_ReturnsFalse>b__1()


System.Net.Tests.HttpResponseStreamTests.CanRead_Get_ReturnsFalse [FAIL]
        Assert.Throws() Failure
        Expected: typeof(System.InvalidOperationException)
        Actual:   typeof(System.NotSupportedException): NotSupported_UnreadableStream. For more information, visit http://go.microsoft.com/fwlink/?Lin
  kId=623485
        Stack Trace:
              at xunit.console.netcore!<BaseAddress>+0xb41398
              at System.Net.Tests.HttpResponseStreamTests.<>c__DisplayClass12_0.<CanRead_Get_ReturnsFalse>b__1()
     System.Net.Tests.HttpResponseStreamTests.Write_NullBuffer_ThrowsArgumentNullException [FAIL]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

This is the implementation of the 3-parameter overload on Stream:

        public Task<int> ReadAsync(Byte[] buffer, int offset, int count)
        {
            return ReadAsync(buffer, offset, count, CancellationToken.None);
        }

It is not virtual and just calls the 4-parameter overload, which is virtual.

If you want to change the behavior of ReadAsync in a subclass of Stream, all you need to do is override the 4-parameter overload. You should not add a new 3-parameter overload to the subclass.

public virtual Task<int> ReadAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken)

You can have the 3-parameter method call the 4-parameter method like this:

public virtual Task<int> ReadAsync(Byte[] buffer, int offset, int count)
{
    return ReadAsync(buffer, offset, count, CancellationToken.None)
}

In other words, our code can call the 4-parameter one by passing in a None token if we don’t have one.