Skip to content
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

Enable single file analyzer in the runtime #50894

Merged
merged 32 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
937f893
Enable single file analyzer in the runtime
Apr 8, 2021
1b3dc8e
Merge branch 'main' into SingleFileAnalyzerOnRuntime
tlakollo Apr 8, 2021
f839417
Add IL3002 to CodeAnalysis.test.ruleset to avoid warning on tests
Apr 9, 2021
f92327e
Merge branch 'SingleFileAnalyzerOnRuntime' of https://github.com/tlak…
Apr 9, 2021
ae1bd07
Fix formating of CustomAttribute
Apr 9, 2021
23828b9
Fix introduced typo
Apr 9, 2021
9ec8520
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 9, 2021
eba095e
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 12, 2021
67dbd63
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 14, 2021
63a395a
Fix some formatting/comments/extra pragma
Apr 14, 2021
91ecb47
Fix UnconditionalSuppressMessage when TFM != NetCoreAppCurrent
Apr 14, 2021
eb6d83a
Add more UnconditionalSuppressMessage support for TFM !=
Apr 14, 2021
4bfc9a8
Fix incompatibility in EventLog.csproj
Apr 14, 2021
6367cb9
Add System.Diagnostics.Tools if TFM is netcoreapp3.0 on
Apr 14, 2021
6bad341
Address some PR comments
Apr 16, 2021
0597dde
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 26, 2021
4786f73
Change code in DependencyContext to not use Lazy
Apr 27, 2021
33f6916
PR feedback
Apr 28, 2021
b232294
Redo changes in MetadataLoadContext.csproj after checking out the main
Apr 28, 2021
2947adb
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
Apr 28, 2021
f120ae9
Delete extra code
Apr 28, 2021
874f872
Disable SingleFileAnalyzer for Microsoft.XmlSerializer.Generator and
Apr 28, 2021
1debcce
Merge branch 'main' into SingleFileAnalyzerOnRuntime
tlakollo Apr 29, 2021
870dc92
Missing message change
Apr 29, 2021
670bdcb
Merge branch 'SingleFileAnalyzerOnRuntime' of https://github.com/tlak…
Apr 29, 2021
dbb0690
PR feedback
tlakollo Apr 29, 2021
0994fec
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 12, 2021
2d47bad
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 12, 2021
df3c4bd
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 14, 2021
c2dc595
Change UnconditionalSuppressMessage for SuppressMessage since SingleFile
tlakollo May 14, 2021
ff7f84f
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 17, 2021
305b675
Merge branch 'main' of https://github.com/dotnet/runtime into SingleF…
tlakollo May 19, 2021
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
2 changes: 2 additions & 0 deletions eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<CodeAnalysisRuleset>$(MSBuildThisFileDirectory)CodeAnalysis.ruleset</CodeAnalysisRuleset>
<!-- Disable analyzers in sourcebuild -->
<RunAnalyzers Condition="'$(DotNetBuildFromSource)' == 'true'">false</RunAnalyzers>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
</PropertyGroup>
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftCodeAnalysisCSharpCodeStyleVersion)" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.ILLink.Analyzers" Version="$(MicrosoftNETILLinkAnalyzerPackageVersion)" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@
<Rule Id="CA5401" Action="None" /> <!-- Do not use CreateEncryptor with non-default IV -->
<Rule Id="CA5402" Action="None" /> <!-- Use CreateEncryptor with the default IV -->
<Rule Id="CA5403" Action="None" /> <!-- Do not hard-code certificate -->
<Rule Id="IL3000" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
<Rule Id="IL3001" Action="None" /> <!-- Avoid using accessing Assembly file path when publishing as a single-file -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="AD0001" Action="None" /> <!-- Analyzer threw an exception -->
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<MicrosoftPrivateIntellisenseVersion>5.0.0-preview-20201009.2</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.2.21205.2</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>6.0.0-preview.4.21179.1</MicrosoftNETCoreRuntimeICUTransportVersion>
<!-- Mono LLVM -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -74,6 +75,7 @@ public DependencyContext Merge(DependencyContext other)
);
}

[RequiresAssemblyFiles(Message = "Calls GetDepsJsonPath")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be propagated to the public API (Default property) - I would expect the analyzer to generate some warnings around this. If not it's a bug in the analyzer which we should fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a little bit today to debug this, seems like a more complicated scenario than I expected. The analyzer is only able to see System.Lazy.Value.get but I have not found a way to connect it with the function is calling (LoadDefault). Also, I tested a similar scenario to see how does the linker behaves using RequiresUnreferencedCode and I found that they both have the same testing hole and don't produce the warning.

public static void Main ()
{
  TestCallsLazyInitializer ();
}

public static Lazy<RequiresUnreferencedCodeCapability> lazyRUC = new Lazy<RequiresUnreferencedCodeCapability> (InitRUC);

[RequiresUnreferencedCode ("Message for --RequiresUnreferencedCodeWithLazyInit--")]
public static RequiresUnreferencedCodeCapability InitRUC ()
{
	RequiresUnreferencedCodeCapability objectRUC = new RequiresUnreferencedCodeCapability ();
	return objectRUC;
}

[ExpectedWarning ("IL2026", "--RequiresUnreferencedCodeWithLazyInit--")]
public static void TestCallsLazyInitializer ()
{
	RequiresUnreferencedCodeCapability objectRUC = lazyRUC.Value;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like dotnet/linker#1912 and related.

We should get a warning in the static constructor, when the Lazy instance is getting constructed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With dotnet/linker#1964 now the Lazy call showed a warning, but since it warns on an implicit static constructor (I cannot annotate the static constructor unless I implement it) and then gets assigned to a field (which is a target that RequiresAssembly files don't support) I couldn't mark it with RequiresAssemblyFiles. I ended up refactoring the code and not make use of the Lazy call.

private static DependencyContext LoadDefault()
{
var entryAssembly = Assembly.GetEntryAssembly();
Expand All @@ -85,6 +87,7 @@ private static DependencyContext LoadDefault()
return Load(entryAssembly);
}

[RequiresAssemblyFiles(Message = "Calls GetDepsJsonPath")]
public static DependencyContext Load(Assembly assembly)
{
return DependencyContextLoader.Default.Load(assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

Expand Down Expand Up @@ -50,6 +51,7 @@ private static Stream GetResourceStream(Assembly assembly, string name)
return assembly.GetManifestResourceStream(name);
}

[RequiresAssemblyFiles(Message = "Calls GetDepsJsonPath")]
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
public DependencyContext Load(Assembly assembly)
{
if (assembly == null)
Expand Down Expand Up @@ -103,6 +105,7 @@ private DependencyContext LoadContext(IDependencyContextReader reader, string lo
return null;
}

[RequiresAssemblyFiles (Message = "Calls GetDepsJsonPath")]
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyContextReader reader)
{
using (Stream stream = GetResourceStream(assembly, assembly.GetName().Name + DepsJsonExtension))
Expand All @@ -125,6 +128,7 @@ private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyCont
return null;
}

[RequiresAssemblyFiles (Message = "Needs additional support for reading .deps.json in single file", Url = "https://github.com/dotnet/runtime/issues/41265")]
private string GetDepsJsonPath(Assembly assembly)
{
// Assemblies loaded in memory (e.g. single file) return empty string from Location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\src\System.Text.Json.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresAssemblyFilesAttribute.cs" />
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
Assembly assm = null;

// look next to requesting assembly
// The code has a fallback to use AppDomain.CurrentDomain.BaseDirectory so is not single file dangerous
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
assemblyPath = args.RequestingAssembly?.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (!string.IsNullOrEmpty(assemblyPath))
{
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
Expand All @@ -50,7 +53,10 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
}

// look next to the executing assembly
// The code has a fallback to use AppDomain.CurrentDomain.BaseDirectory so is not single file dangerous
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
assemblyPath = Assembly.GetExecutingAssembly().Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (!string.IsNullOrEmpty(assemblyPath))
{
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
Expand Down
17 changes: 13 additions & 4 deletions src/libraries/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,23 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
ImportType(type, mappings, importedTypes, warnings, importer, parsableerrors);
}
}
// Only used in diagnostics
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string nameOrLocation = assembly.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (nameOrLocation == string.Empty)
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
nameOrLocation = assembly.FullName;

if (importedTypes.Count > 0)
{
var serializableTypes = (Type[])importedTypes.ToArray(typeof(Type));
var allMappings = (XmlMapping[])mappings.ToArray(typeof(XmlMapping));

bool gac = assembly.GlobalAssemblyCache;
outputDirectory = outputDirectory == null ? (gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location)) : outputDirectory;
// Code has a fallback in case the location is null
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
outputDirectory = outputDirectory == null ? (gac ? Environment.CurrentDirectory : Path.GetDirectoryName(assembly.Location)) : outputDirectory;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file

if (!Directory.Exists(outputDirectory))
{
Expand Down Expand Up @@ -369,17 +378,17 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
if (!silent)
{
Console.Out.WriteLine(SR.Format(SR.InfoFileName, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedFile, assembly.Location, codePath));
Console.Out.WriteLine(SR.Format(SR.InfoGeneratedFile, nameOrLocation, codePath));
}
}
else
{
Console.Out.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrGenerationFailed, assembly.Location)));
Console.Out.WriteLine(FormatMessage(parsableerrors, false, SR.Format(SR.ErrGenerationFailed, nameOrLocation)));
}
}
else
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoNoSerializableTypes, assembly.Location)));
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoNoSerializableTypes, nameOrLocation)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ private static Assembly LoadAssembly(string codeBase)
catch (ArgumentException)
{
assemblyName = new AssemblyName();
// Setting a CodeBase is not single-file dangerous
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
assemblyName.CodeBase = codeBase;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
// Assemblies loaded in memory return empty string from Location.
// Suppressing the warning until gets fixed, see https://github.com/dotnet/runtime/issues/50821
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string location = asm.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (location == string.Empty)
continue;

Expand All @@ -101,7 +104,10 @@ public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
}
else
{
// Suppressing the warning until gets fixed, see https://github.com/dotnet/runtime/issues/50821
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string location = resourceAssembly.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (location != string.Empty)
{
string fileName = Path.GetFileName(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private ClientConfigPaths(string exePath, bool includeUserConfig)
exeAssembly = Assembly.GetEntryAssembly();

// in case of SingleFile deployment, Assembly.Location is empty.
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (exeAssembly?.Location.Length == 0)
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
{
isSingleFile = true;
HasEntryAssembly = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,10 @@ internal static string GetDllPath(string machineName)
if (machineName == "." && !File.Exists(dllPath))
{
// use this assembly directory
// The code handles if the path is null by calling AppContext.BaseDirectory
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string assmLocation = typeof(EventLog).Assembly.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (!string.IsNullOrEmpty(assmLocation))
{
dllPath = Path.Combine(Path.GetDirectoryName(assmLocation), AltDllName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ private static string GetBaseDirectoryCore()
#if CORERT
string? path = Environment.ProcessPath;
#else
// Single File apps should always set APP_CONTEXT_BASE_DIRECTORY therefore code handles Assembly.Location equals null
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string? path = Assembly.GetEntryAssembly()?.Location;
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
#endif

string? directory = Path.GetDirectoryName(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ namespace System.Diagnostics.CodeAnalysis
AttributeTargets.Property,
Inherited = false,
AllowMultiple = false)]
public sealed class RequiresAssemblyFilesAttribute : Attribute
#if SYSTEM_PRIVATE_CORELIB
public
#else
internal
#endif
sealed class RequiresAssemblyFilesAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiresAssemblyFilesAttribute"/> class.
Expand All @@ -32,4 +37,4 @@ public RequiresAssemblyFilesAttribute() { }
/// </summary>
public string? Url { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public virtual IEnumerable<Type> ExportedTypes
public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; }
public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }

[RequiresAssemblyFiles(Message = "Calls 'AssemblyName.EscapeCodeBase(string)' which is a dangerous single file pattern")]
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
public virtual string EscapedCodeBase => AssemblyName.EscapeCodeBase(CodeBase);

[RequiresUnreferencedCode("Assembly.CreateInstance is not supported with trimming. Use Type.GetType instead.")]
Expand Down Expand Up @@ -152,6 +153,7 @@ public virtual IEnumerable<Type> ExportedTypes
public virtual Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) { throw NotImplemented.ByDesign; }

public virtual FileStream? GetFile(string name) { throw NotImplemented.ByDesign; }
[RequiresAssemblyFiles(Message = "'System.Reflection.Assembly.GetFiles(bool)' will throw for assemblies embedded in a single-file app", Url = "https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/il3001")]
tlakollo marked this conversation as resolved.
Show resolved Hide resolved
public virtual FileStream[] GetFiles() => GetFiles(getResourceModules: false);
public virtual FileStream[] GetFiles(bool getResourceModules) { throw NotImplemented.ByDesign; }

Expand Down Expand Up @@ -268,6 +270,7 @@ public static Assembly LoadFile(string path)
}

[RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
[RequiresAssemblyFiles (Message = "Calling 'System.Reflection.Assembly.LoadFromResolveHandler' will return a null assembly for assemblies embedded in a single-file app")]
private static Assembly? LoadFromResolveHandler(object? sender, ResolveEventArgs args)
{
Assembly? requestingAssembly = args.RequestingAssembly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Configuration.Assemblies;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.Text;
using CultureInfo = System.Globalization.CultureInfo;
Expand Down Expand Up @@ -59,12 +60,14 @@ public string? CultureName
set => _cultureInfo = (value == null) ? null : new CultureInfo(value);
}

[RequiresAssemblyFiles (Message = "'System.Reflection.AssemblyName.CodeBase' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'", Url = "https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/il3000")]
public string? CodeBase
{
get => _codeBase;
set => _codeBase = value;
}

[RequiresAssemblyFiles (Message = "'System.Reflection.AssemblyName.EscapedCodeBase' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'", Url = "https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/il3000")]
public string? EscapedCodeBase
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,10 @@ public void Dispose()
handler.Method.Name,
this != AssemblyLoadContext.Default ? ToString() : Name,
resolvedAssembly?.FullName,
// This call is fine because the code handles the Assembly.Location equals null
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
resolvedAssembly != null && !resolvedAssembly.IsDynamic ? resolvedAssembly.Location : null);
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
}
#endif // CORECLR
if (resolvedAssembly != null)
Expand Down Expand Up @@ -738,7 +741,10 @@ private static void OnAssemblyLoad(RuntimeAssembly assembly)
name,
handler.Method.Name,
asm?.FullName,
// This call is fine because the code handles the Assembly.Location equals null
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
asm != null && !asm.IsDynamic ? asm.Location : null);
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
}
#endif // CORECLR
RuntimeAssembly? ret = GetRuntimeAssembly(asm);
Expand Down Expand Up @@ -768,7 +774,10 @@ private static void OnAssemblyLoad(RuntimeAssembly assembly)

AssemblyLoadContext parentALC = GetLoadContext(parentAssembly)!;

// This call is fine because native call runs before this and checks BindSatelliteResourceFromBundle
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
string? parentDirectory = Path.GetDirectoryName(parentAssembly.Location);
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
if (parentDirectory == null)
return null;

Expand Down
Loading