File tree Expand file tree Collapse file tree 5 files changed +37
-7
lines changed
src/Smdn.Net.AddressResolution Expand file tree Collapse file tree 5 files changed +37
-7
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 11// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
22// SPDX-License-Identifier: MIT
33using System ;
4+ using System . Runtime . InteropServices ;
45
56namespace 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 )
Original file line number Diff line number Diff line change 66#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
77using System . Runtime . ExceptionServices ;
88#endif
9+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10+ using System . Runtime . Versioning ;
11+ #endif
912using System . Threading ;
1013using System . Threading . Tasks ;
1114
1720
1821namespace Smdn . Net . AddressTables ;
1922
23+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
24+ [ SupportedOSPlatform ( "windows" ) ]
25+ #endif
2026public 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 ) ;
Original file line number Diff line number Diff line change 22// SPDX-License-Identifier: MIT
33using System ;
44using System . Collections . Generic ;
5- #if NULL_STATE_STATIC_ANALYSIS_ATTRIBUTES
6- using System . Diagnostics . CodeAnalysis ;
7- #endif
85using System . Globalization ;
96using System . IO ;
107using System . Net ;
1512using Microsoft . Extensions . DependencyInjection ;
1613using 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+
1822namespace Smdn . Net . AddressTables ;
1923
2024public sealed class ProcfsArpAddressTable : AddressTable {
Original file line number Diff line number Diff line change 66#if SYSTEM_RUNTIME_EXCEPTIONSERVICES_EXCEPTIONDISPATCHINFO_SETCURRENTSTACKTRACE
77using System . Runtime . ExceptionServices ;
88#endif
9+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
10+ using System . Runtime . Versioning ;
11+ #endif
912using System . Threading ;
1013using System . Threading . Tasks ;
1114
1922
2023namespace Smdn . Net . NetworkScanning ;
2124
25+ #if SYSTEM_RUNTIME_VERSIONING_SUPPORTEDOSPLATFORMATTRIBUTE
26+ [ SupportedOSPlatform ( "windows" ) ]
27+ #endif
2228public 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 ) ;
You can’t perform that action at this time.
0 commit comments