Skip to content

Commit

Permalink
fix: NonDisposableStream not available netcore3.1 (#263)
Browse files Browse the repository at this point in the history
* NonDisposableStream is not available when running Spark.Web which is a
  .net core 3.1 web application
* Fixes TypeLoadException: "Could not load type
  Microsoft.AspNetCore.Mvc.Internal.NonDisposableStream from assembly
  Microsoft.AspNetCore.Mvc.Core."
  • Loading branch information
kennethmyhra authored Aug 17, 2020
1 parent 6ace836 commit 8e71c3d
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using Hl7.Fhir.Serialization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.WebUtilities;
using Spark.Core;
using Spark.Engine.Extensions;
using Spark.Engine.IO;
using System;
using System.Diagnostics;
using System.IO;
Expand Down
140 changes: 140 additions & 0 deletions src/Spark.Engine/IO/NonDisposableStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Spark.Engine.IO
{
internal class NonDisposableStream : Stream
{
private readonly Stream _innerStream;

public NonDisposableStream(Stream innerStream)
{
_innerStream = innerStream;
}

/// <inheritdoc/>
public override bool CanRead => _innerStream.CanRead;

/// <inheritdoc/>
public override bool CanSeek => _innerStream.CanSeek;

/// <inheritdoc/>
public override bool CanWrite => _innerStream.CanWrite;

/// <inheritdoc/>
public override long Length => _innerStream.Length;

/// <inheritdoc/>
public override long Position { get => _innerStream.Position; set => _innerStream.Position = value; }

/// <inheritdoc/>
public override void Flush()
{

}

/// <inheritdoc/>
public override int Read(byte[] buffer, int offset, int count)
{
return _innerStream.Read(buffer, offset, count);
}

/// <inheritdoc/>
public override long Seek(long offset, SeekOrigin origin)
{
return _innerStream.Seek(offset, origin);
}

/// <inheritdoc/>
public override void SetLength(long value)
{
_innerStream.SetLength(value);
}

/// <inheritdoc/>
public override void Write(byte[] buffer, int offset, int count)
{
_innerStream.Write(buffer, offset, count);
}

/// <inheritdoc/>
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
}

/// <inheritdoc/>
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
return _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
}

/// <inheritdoc/>
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _innerStream.BeginRead(buffer, offset, count, callback, state);
}

/// <inheritdoc/>
public override int EndRead(IAsyncResult asyncResult)
{
return _innerStream.EndRead(asyncResult);
}

/// <inheritdoc/>
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _innerStream.BeginWrite(buffer, offset, count, callback, state);
}

/// <inheritdoc/>
public override void EndWrite(IAsyncResult asyncResult)
{
_innerStream.EndWrite(asyncResult);
}

/// <inheritdoc/>
public override bool CanTimeout => _innerStream.CanTimeout;

/// <inheritdoc/>
public override void Close()
{
// Don't want to close the underlying stream, therefore we not doing anything here
}

/// <inheritdoc/>
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken);
}

/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
// Don't want to close the underlying stream, therefore we not doing anything here
}

/// <inheritdoc/>
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _innerStream.FlushAsync(cancellationToken);
}

/// <inheritdoc/>
public override int ReadByte()
{
return _innerStream.ReadByte();
}

/// <inheritdoc/>
public override void WriteByte(byte value)
{
_innerStream.WriteByte(value);
}

/// <inheritdoc/>
public override int ReadTimeout { get => _innerStream.ReadTimeout; set => _innerStream.ReadTimeout = value; }
}
}

0 comments on commit 8e71c3d

Please sign in to comment.