Skip to content

Commit e2941f4

Browse files
authored
Merge pull request #631 from Sergio0694/user/sergiopedri/fix-aot-warnings
Fix AOT warnings
2 parents bb95bb5 + 9ad5e19 commit e2941f4

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/AsmResolver.DotNet/DotNetCorePathProvider.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,26 @@ private void DetectInstalledRuntimes(string installationDirectory)
196196
// with the help of System.Reflection. The assembly of System.Object is either System.Runtime
197197
// or System.Private.CoreLib, which is located at <installation_directory>/shared/<runtime>/<version>/.
198198

199-
string corlibPath = typeof(object).Assembly.Location;
200-
string versionPath = Path.GetDirectoryName(corlibPath)!;
201-
string runtimePath = Path.GetDirectoryName(versionPath)!;
202-
string sharedPath = Path.GetDirectoryName(runtimePath)!;
203-
return Path.GetDirectoryName(sharedPath);
199+
#if NET8_0_OR_GREATER
200+
[UnconditionalSuppressMessage("SingleFile", "IL3000", Justification = "We're explicitly checking for this scenario.")]
201+
#endif
202+
static string? TryGetObjectCoreLibPath()
203+
{
204+
string corlibPath = typeof(object).Assembly.Location;
205+
206+
// The path will be empty when publishing as single-file
207+
if (string.IsNullOrEmpty(corlibPath))
208+
{
209+
return null;
210+
}
211+
212+
string versionPath = Path.GetDirectoryName(corlibPath)!;
213+
string runtimePath = Path.GetDirectoryName(versionPath)!;
214+
string sharedPath = Path.GetDirectoryName(runtimePath)!;
215+
return Path.GetDirectoryName(sharedPath);
216+
}
217+
218+
return TryGetObjectCoreLibPath();
204219
}
205220

206221
return null;

src/AsmResolver.DotNet/ModuleDefinition.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ public static ModuleDefinition FromModuleBaseAddress(IntPtr hInstance, PEMapping
164164
public static ModuleDefinition FromModule(Module module) => FromModule(module, new ModuleReaderParameters());
165165

166166
/// <summary>
167-
/// Opens a module from an instance of a <see cref="System.Reflection.Module"/>.
167+
/// Opens a module from an instance of a <see cref="Module"/>.
168168
/// </summary>
169169
/// <param name="module">The reflection module to load.</param>
170170
/// <param name="readerParameters">The parameters to use while reading the module.</param>
171171
/// <returns>The module.</returns>
172+
#if NET8_0_OR_GREATER
173+
[UnconditionalSuppressMessage("SingleFile", "IL3002", Justification = "We're explicitly checking for unmapped module names.")]
174+
#endif
172175
public static ModuleDefinition FromModule(Module module, ModuleReaderParameters readerParameters)
173176
{
174177
if (!ReflectionHacks.TryGetHINSTANCE(module, out var handle))

src/AsmResolver.DotNet/ReflectionHacks.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Reflection;
34
using System.Runtime.InteropServices;
45
using AsmResolver.Collections;
@@ -72,6 +73,9 @@ internal static Type[] GetFunctionPointerParameterTypes(Type t)
7273
#endif
7374
}
7475

76+
#if NET8_0_OR_GREATER
77+
[UnconditionalSuppressMessage("SingleFile", "IL3002", Justification = "Callers are explicitly checking for '-1'.")]
78+
#endif
7579
internal static bool TryGetHINSTANCE(Module m, out nint hinstance)
7680
{
7781
#if !NETSTANDARD2_0

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
44

55
<PropertyGroup>
6-
<TargetFrameworks>net8.0;net6.0;net462;net472;net35;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
6+
<TargetFrameworks>net9.0;net8.0;net6.0;net462;net472;net35;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Nullable>enable</Nullable>
99
<IsTrimmable>true</IsTrimmable>

0 commit comments

Comments
 (0)