Skip to content

Commit 5e41166

Browse files
authored
Use the built in versioning macros that exist in .NET Core/SDK projects (#122)
NET45 specifically means .NET 4.5, not 4.5.1 or 4.5.2. The project had been redefining that macro with a different meaning. Also some of the places this code was using `#if NET45` should really use `#if NETFRAMEWORK`
1 parent 6e57320 commit 5e41166

File tree

9 files changed

+19
-25
lines changed

9 files changed

+19
-25
lines changed

src/Microsoft.Azure.Relay/Common/AsyncLock.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ void Dispose(bool disposing)
7777
if (disposing)
7878
{
7979
this.asyncSemaphore.Dispose();
80-
#if NET45
80+
8181
// This is only disposing the Task...
8282
this.lockRelease.Dispose();
83-
#endif
8483
}
8584

8685
this.disposed = true;

src/Microsoft.Azure.Relay/Common/Fx.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ public static bool IsFatal(Exception exception)
3131
{
3232
while (exception != null)
3333
{
34-
// FYI, CallbackException is-a FatalException
35-
if (
36-
//exception is FatalException ||
37-
#if NET45
38-
(exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
34+
if (exception is AccessViolationException ||
3935
exception is ThreadAbortException ||
40-
exception is AccessViolationException ||
41-
#endif
36+
(exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
4237
exception is SEHException)
4338
{
4439
return true;

src/Microsoft.Azure.Relay/Common/PlatformHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace Microsoft.Azure.Relay
66
using System;
77
using System.IO;
88

9-
static class PlatformExtensions
9+
static class PlatformHelpers
1010
{
1111
public static ArraySegment<byte> GetArraySegment(this MemoryStream memoryStream)
1212
{
1313
Fx.Assert(memoryStream != null, "memoryStream is required");
1414

1515
ArraySegment<byte> buffer;
16-
#if NET45
16+
#if NET45 || NET451 || NET452
1717
buffer = new ArraySegment<byte>(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
1818
#else
1919
// .NET 4.6 and .NET Core added MemoryStream.TryGetBuffer()

src/Microsoft.Azure.Relay/HybridConnectionUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Azure.Relay
88
using System.Collections.Specialized;
99
using System.Net;
1010
using System.Text;
11-
#if NET45
11+
#if NETFRAMEWORK
1212
using System.Web;
1313
#else
1414
// NETSTANDARD
@@ -53,7 +53,7 @@ public static Uri BuildUri(string host, int port, string path, string query, str
5353
}.Uri;
5454
}
5555

56-
#if NET45
56+
#if NETFRAMEWORK
5757
public static NameValueCollection ParseQueryString(string queryString)
5858
{
5959
return HttpUtility.ParseQueryString(queryString);

src/Microsoft.Azure.Relay/HybridHttpConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public override async Task WriteAsync(byte[] array, int offset, int count, Cance
454454
}
455455
}
456456

457-
#if NET45
457+
#if NETFRAMEWORK
458458
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
459459
{
460460
return this.WriteAsync(buffer, offset, count).ToAsyncResult(callback, state);
@@ -464,7 +464,7 @@ public override void EndWrite(IAsyncResult asyncResult)
464464
{
465465
TaskEx.EndAsyncResult(asyncResult);
466466
}
467-
#endif // NET45
467+
#endif // NETFRAMEWORK
468468

469469
public override string ToString()
470470
{

src/Microsoft.Azure.Relay/Microsoft.Azure.Relay.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>This is the Azure Relay .NET Standard client library for Hybrid Connections. For more information about Relay see https://azure.microsoft.com/en-us/services/service-bus/.
@@ -30,7 +30,7 @@
3030

3131
<!-- .NET Framework specific -->
3232
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
33-
<DefineConstants>$(DefineConstants);NET45</DefineConstants>
33+
<DefineConstants>$(DefineConstants)</DefineConstants>
3434
</PropertyGroup>
3535
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
3636
<Reference Include="System.Net.Http" />
@@ -40,7 +40,7 @@
4040

4141
<!-- .NET Standard specific -->
4242
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
43-
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
43+
<DefineConstants>$(DefineConstants)</DefineConstants>
4444
</PropertyGroup>
4545
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
4646
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="1.0.0" />

src/Microsoft.Azure.Relay/WebSocketMessageStream.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public override int Read(byte[] buffer, int offset, int count)
6565
return this.ReadAsync(buffer, offset, count).ConfigureAwait(false).GetAwaiter().GetResult();
6666
}
6767

68-
#if NET45
68+
#if NETFRAMEWORK
6969
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
7070
{
7171
return this.ReadAsync(buffer, offset, count).ToAsyncResult(callback, state);
@@ -75,7 +75,7 @@ public override int EndRead(IAsyncResult asyncResult)
7575
{
7676
return TaskEx.EndAsyncResult<int>(asyncResult);
7777
}
78-
#endif // NET45
78+
#endif // NETFRAMEWORK
7979

8080
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
8181
{

src/Microsoft.Azure.Relay/WebSocketStream.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
120120
}
121121
}
122122

123-
#if NET45
123+
#if NETFRAMEWORK
124124
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
125125
{
126126
return this.ReadAsync(buffer, offset, count, CancellationToken.None).ToAsyncResult(callback, state, true);
@@ -130,7 +130,7 @@ public override int EndRead(IAsyncResult asyncResult)
130130
{
131131
return TaskEx.EndAsyncResult<int>(asyncResult);
132132
}
133-
#endif // NET45
133+
#endif // NETFRAMEWORK
134134

135135
public override long Seek(long offset, SeekOrigin origin)
136136
{
@@ -185,7 +185,7 @@ await this.webSocket.SendAsync(
185185
}
186186
}
187187

188-
#if NET45
188+
#if NETFRAMEWORK
189189
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
190190
{
191191
return this.WriteAsync(buffer, offset, count, CancellationToken.None).ToAsyncResult(callback, state, true);
@@ -195,7 +195,7 @@ public override void EndWrite(IAsyncResult asyncResult)
195195
{
196196
TaskEx.EndAsyncResult(asyncResult);
197197
}
198-
#endif // NET45
198+
#endif // NETFRAMEWORK
199199

200200
internal void Abort()
201201
{

test/Microsoft.Azure.Relay.UnitTests/Microsoft.Azure.Relay.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</ItemGroup>
2727

2828
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' ">
29-
<DefineConstants>$(DefineConstants);NET46</DefineConstants>
29+
<DefineConstants>$(DefineConstants)</DefineConstants>
3030
</PropertyGroup>
3131

3232
</Project>

0 commit comments

Comments
 (0)