Skip to content

Fix AOT warnings #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/AsmResolver.DotNet/DotNetCorePathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,26 @@ private void DetectInstalledRuntimes(string installationDirectory)
// with the help of System.Reflection. The assembly of System.Object is either System.Runtime
// or System.Private.CoreLib, which is located at <installation_directory>/shared/<runtime>/<version>/.

string corlibPath = typeof(object).Assembly.Location;
string versionPath = Path.GetDirectoryName(corlibPath)!;
string runtimePath = Path.GetDirectoryName(versionPath)!;
string sharedPath = Path.GetDirectoryName(runtimePath)!;
return Path.GetDirectoryName(sharedPath);
#if NET8_0_OR_GREATER
[UnconditionalSuppressMessage("SingleFile", "IL3000", Justification = "We're explicitly checking for this scenario.")]
#endif
static string? TryGetObjectCoreLibPath()
{
string corlibPath = typeof(object).Assembly.Location;

// The path will be empty when publishing as single-file
if (string.IsNullOrEmpty(corlibPath))
{
return null;
}

string versionPath = Path.GetDirectoryName(corlibPath)!;
string runtimePath = Path.GetDirectoryName(versionPath)!;
string sharedPath = Path.GetDirectoryName(runtimePath)!;
return Path.GetDirectoryName(sharedPath);
}

return TryGetObjectCoreLibPath();
}

return null;
Expand Down
5 changes: 4 additions & 1 deletion src/AsmResolver.DotNet/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ public static ModuleDefinition FromModuleBaseAddress(IntPtr hInstance, PEMapping
public static ModuleDefinition FromModule(Module module) => FromModule(module, new ModuleReaderParameters());

/// <summary>
/// Opens a module from an instance of a <see cref="System.Reflection.Module"/>.
/// Opens a module from an instance of a <see cref="Module"/>.
/// </summary>
/// <param name="module">The reflection module to load.</param>
/// <param name="readerParameters">The parameters to use while reading the module.</param>
/// <returns>The module.</returns>
#if NET8_0_OR_GREATER
[UnconditionalSuppressMessage("SingleFile", "IL3002", Justification = "We're explicitly checking for unmapped module names.")]
#endif
public static ModuleDefinition FromModule(Module module, ModuleReaderParameters readerParameters)
{
if (!ReflectionHacks.TryGetHINSTANCE(module, out var handle))
Expand Down
4 changes: 4 additions & 0 deletions src/AsmResolver.DotNet/ReflectionHacks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
using AsmResolver.Collections;
Expand Down Expand Up @@ -72,6 +73,9 @@ internal static Type[] GetFunctionPointerParameterTypes(Type t)
#endif
}

#if NET8_0_OR_GREATER
[UnconditionalSuppressMessage("SingleFile", "IL3002", Justification = "Callers are explicitly checking for '-1'.")]
#endif
internal static bool TryGetHINSTANCE(Module m, out nint hinstance)
{
#if !NETSTANDARD2_0
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;net462;net472;net35;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net6.0;net462;net472;net35;netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Nullable>enable</Nullable>
<IsTrimmable>true</IsTrimmable>
Expand Down
Loading