Skip to content

Commit 9dc9b2b

Browse files
committed
Work around missing features in netstandard1.3
- get classes now included in NetCore assembly compiling - `SerializationAttribute` is not available - therefore `Exception` is not serializable - therefore `DefaultContractResolver.IgnoreSerializableAttribute` is not available - `Stream.(Begin|End)(Read|Write)` and `Stream.Close()` are not available nit: clean up `MultipartFormDataStreamProvider` whitespace
1 parent 21eb655 commit 9dc9b2b

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

src/System.Net.Http.Formatting/Formatting/JsonContractResolver.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ public JsonContractResolver(MediaTypeFormatter formatter)
2929
}
3030

3131
_formatter = formatter;
32+
33+
#if !NETFX_CORE
3234
// Need this setting to have [Serializable] types serialized correctly
3335
IgnoreSerializableAttribute = false;
36+
#endif
3437
}
3538

3639
// Determines whether a member is required or not and sets the appropriate JsonProperty settings

src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ public override long Position
111111
}
112112
}
113113

114+
#if !NETFX_CORE // BeginX and EndX are not supported on streams in portable libraries
114115
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
115116
{
116117
return base.BeginRead(buffer, offset, PrepareStreamForRangeRead(count), callback, state);
117118
}
119+
#endif
118120

119121
public override int Read(byte[] buffer, int offset, int count)
120122
{
@@ -172,6 +174,7 @@ public override void Write(byte[] buffer, int offset, int count)
172174
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
173175
}
174176

177+
#if !NETFX_CORE // BeginX and EndX are not supported on streams in portable libraries
175178
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
176179
{
177180
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
@@ -181,6 +184,7 @@ public override void EndWrite(IAsyncResult asyncResult)
181184
{
182185
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
183186
}
187+
#endif
184188

185189
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
186190
{

src/System.Net.Http.Formatting/Internal/NonClosingDelegatingStream.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace System.Net.Http.Internal
88
/// <summary>
99
/// Stream that doesn't close the inner stream when closed. This is to work around a limitation
1010
/// in the <see cref="System.Xml.XmlDictionaryReader"/> insisting of closing the inner stream.
11-
/// The regular <see cref="System.Xml.XmlReader"/> does allow for not closing the inner stream but that
12-
/// doesn't have the quota that we need for security reasons. Implementations of
11+
/// The regular <see cref="System.Xml.XmlReader"/> does allow for not closing the inner stream but that
12+
/// doesn't have the quota that we need for security reasons. Implementations of
1313
/// <see cref="System.Net.Http.Formatting.MediaTypeFormatter"/>
1414
/// should not close the input stream when reading or writing so hence this workaround.
1515
/// </summary>
@@ -20,8 +20,14 @@ public NonClosingDelegatingStream(Stream innerStream)
2020
{
2121
}
2222

23+
#if NETFX_CORE
24+
protected override void Dispose(bool disposing)
25+
{
26+
}
27+
#else
2328
public override void Close()
2429
{
2530
}
31+
#endif
2632
}
2733
}

src/System.Net.Http.Formatting/InvalidByteRangeException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace System.Net.Http
1010
{
1111
/// <summary>
12-
/// An exception thrown by <see cref="ByteRangeStreamContent"/> in case none of the requested ranges
12+
/// An exception thrown by <see cref="ByteRangeStreamContent"/> in case none of the requested ranges
1313
/// overlap with the current extend of the selected resource. The current extend of the resource
1414
/// is indicated in the ContentRange property.
1515
/// </summary>
@@ -35,11 +35,13 @@ public InvalidByteRangeException(ContentRangeHeaderValue contentRange, string me
3535
Initialize(contentRange);
3636
}
3737

38+
#if !NETFX_CORE // Exception is not serializable in netstandard1.3.
3839
public InvalidByteRangeException(ContentRangeHeaderValue contentRange, SerializationInfo info, StreamingContext context)
3940
: base(info, context)
4041
{
4142
Initialize(contentRange);
4243
}
44+
#endif
4345

4446
/// <summary>
4547
/// The current extend of the resource indicated in terms of a ContentRange header field.

src/System.Net.Http.Formatting/MultipartFormDataStreamProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
namespace System.Net.Http
1212
{
1313
/// <summary>
14-
/// A <see cref="MultipartStreamProvider"/> implementation suited for use with HTML file uploads for writing file
15-
/// content to a <see cref="FileStream"/>. The stream provider looks at the <b>Content-Disposition</b> header
14+
/// A <see cref="MultipartStreamProvider"/> implementation suited for use with HTML file uploads for writing file
15+
/// content to a <see cref="FileStream"/>. The stream provider looks at the <b>Content-Disposition</b> header
1616
/// field and determines an output <see cref="Stream"/> based on the presence of a <b>filename</b> parameter.
17-
/// If a <b>filename</b> parameter is present in the <b>Content-Disposition</b> header field then the body
17+
/// If a <b>filename</b> parameter is present in the <b>Content-Disposition</b> header field then the body
1818
/// part is written to a <see cref="FileStream"/>, otherwise it is written to a <see cref="MemoryStream"/>.
19-
/// This makes it convenient to process MIME Multipart HTML Form data which is a combination of form
19+
/// This makes it convenient to process MIME Multipart HTML Form data which is a combination of form
2020
/// data and file content.
2121
/// </summary>
2222
public class MultipartFormDataStreamProvider : MultipartFileStreamProvider
@@ -52,7 +52,7 @@ public MultipartFormDataStreamProvider(string rootPath, int bufferSize)
5252

5353
/// <summary>
5454
/// This body part stream provider examines the headers provided by the MIME multipart parser
55-
/// and decides whether it should return a file stream or a memory stream for the body part to be
55+
/// and decides whether it should return a file stream or a memory stream for the body part to be
5656
/// written to.
5757
/// </summary>
5858
/// <param name="parent">The parent MIME multipart HttpContent instance.</param>

test/System.Net.Http.Formatting.Test/Internal/ByteRangeStreamTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public async Task Position_PositionsNextRead()
303303
}
304304
}
305305

306+
#if !NETFX_CORE // BeginX and EndX are not supported on streams in portable libraries
306307
[Theory]
307308
[PropertyData("ReadBoundsDataWithLimit")]
308309
public void BeginRead_ReadsEffectiveLengthBytes(int from, int to, int innerLength, int effectiveLength)
@@ -330,6 +331,7 @@ public void BeginRead_ReadsEffectiveLengthBytes(int from, int to, int innerLengt
330331
Assert.Equal(effectiveLength, rangeStream.Position);
331332
}
332333
}
334+
#endif
333335

334336
[Fact]
335337
public async Task BeginRead_CanReadAfterLength()

0 commit comments

Comments
 (0)