Skip to content

Commit 68e9f9c

Browse files
committed
bump Vanara.PInvoke.IpHlpApi up to 4.1.1
1 parent 9e4750f commit 68e9f9c

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

src/Smdn.Net.AddressResolution/Smdn.Net.AddressResolution.csproj

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ This library also provides a functionality for referencing the system's address
4040
<PackageReference Include="Microsoft.Bcl.HashCode" />
4141
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
4242
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
43-
<PackageReference Include="Vanara.PInvoke.IpHlpApi" Version="3.4.13" />
43+
<PackageReference Include="Vanara.Core" Version="4.1.1">
44+
<!--
45+
`Vanara.Core` imports code analysis attributes such as `NotNullWhenAttributes` for backward compatibility.
46+
Therefore, depending on the configuration of <TargetFramework>s, this may conflict with
47+
type names imported from the assembly `netstandard`.
48+
So, define separate namespaces with the Aliases property, and allow names imported from each
49+
assembly to be referenced separately by using `extern aliases`.
50+
-->
51+
<Aliases>VanaraCore</Aliases>
52+
</PackageReference>
53+
<PackageReference Include="Vanara.PInvoke.IpHlpApi" Version="4.1.1" />
4454
</ItemGroup>
4555

4656
<ItemGroup>

src/Smdn.Net.AddressResolution/Smdn.Net.AddressTables/AddressTable.Create.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
22
// SPDX-License-Identifier: MIT
33
using System;
4+
using System.Runtime.InteropServices;
45

56
namespace Smdn.Net.AddressTables;
67

@@ -11,7 +12,7 @@ public static IAddressTable Create(
1112
IServiceProvider? serviceProvider = null
1213
)
1314
{
14-
if (IpHlpApiAddressTable.IsSupported)
15+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && IpHlpApiAddressTable.IsSupported)
1516
return new IpHlpApiAddressTable(serviceProvider);
1617

1718
if (ProcfsArpAddressTable.IsSupported)

src/Smdn.Net.AddressResolution/Smdn.Net.AddressTables/IpHlpApiAddressTable.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
77
using System.Runtime.ExceptionServices;
88
#endif
9+
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10+
using System.Runtime.Versioning;
11+
#endif
912
using System.Threading;
1013
using System.Threading.Tasks;
1114

@@ -17,6 +20,9 @@
1720

1821
namespace Smdn.Net.AddressTables;
1922

23+
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
24+
[SupportedOSPlatform("windows")]
25+
#endif
2026
public sealed class IpHlpApiAddressTable : AddressTable {
2127
public static bool IsSupported => LazyIsSupported.Value;
2228

@@ -50,6 +56,9 @@ [EnumeratorCancellation] CancellationToken cancellationToken
5056
{
5157
using var table = await GetIpNetTable2Async().ConfigureAwait(false);
5258

59+
if (table.Table is null)
60+
yield break;
61+
5362
foreach (var ipnetRow2 in table.Table) {
5463
cancellationToken.ThrowIfCancellationRequested();
5564

@@ -82,7 +91,7 @@ ValueTask<MIB_IPNET_TABLE2> GetIpNetTable2Async()
8291

8392
table.Dispose();
8493

85-
var ex = ret.GetException();
94+
var ex = ret.GetException() ?? new InvalidOperationException($"GetIpNetTable2 failed: {ret}");
8695

8796
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
8897
ex = ExceptionDispatchInfo.SetCurrentStackTrace(ex);

src/Smdn.Net.AddressResolution/Smdn.Net.AddressTables/ProcfsArpAddressTable.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// SPDX-License-Identifier: MIT
33
using System;
44
using System.Collections.Generic;
5-
#if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
6-
using System.Diagnostics.CodeAnalysis;
7-
#endif
85
using System.Globalization;
96
using System.IO;
107
using System.Net;
@@ -15,6 +12,13 @@
1512
using Microsoft.Extensions.DependencyInjection;
1613
using Microsoft.Extensions.Logging;
1714

15+
#if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
16+
// `Vanara.Core` imports code analysis attributes such as `NotNullWhenAttributes`.
17+
// Since there is a name conflict between `Vanara.Core` and `netstandard`, assign a different
18+
// alias to `Vanara.Core` in csproj and refer to the netstandard name by the global alias here.
19+
using NotNullWhenAttribute = global::System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
20+
#endif
21+
1822
namespace Smdn.Net.AddressTables;
1923

2024
public sealed class ProcfsArpAddressTable : AddressTable {

src/Smdn.Net.AddressResolution/Smdn.Net.NetworkScanning/IpHlpApiNetworkScanner.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
77
using System.Runtime.ExceptionServices;
88
#endif
9+
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10+
using System.Runtime.Versioning;
11+
#endif
912
using System.Threading;
1013
using System.Threading.Tasks;
1114

@@ -19,6 +22,9 @@
1922

2023
namespace Smdn.Net.NetworkScanning;
2124

25+
#if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
26+
[SupportedOSPlatform("windows")]
27+
#endif
2228
public sealed class IpHlpApiNetworkScanner : NetworkScanner {
2329
// ref:
2430
// https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src/wpd_sdk/error-constants.md
@@ -125,7 +131,7 @@ IPAddress address
125131

126132
Logger?.LogWarning("ResolveIpNetEntry2({Address}) {Result}", address, ret.ToString());
127133

128-
var ex = ret.GetException();
134+
var ex = ret.GetException() ?? new InvalidOperationException($"ResolveIpNetEntry2({address}) failed: {ret}");
129135

130136
#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
131137
ex = ExceptionDispatchInfo.SetCurrentStackTrace(ex);

0 commit comments

Comments
 (0)