-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix getting resource when ResourceResolve returns assembly with resou…
…rce that is an assembly ref (#112810) When getting a resource where `ResourceResolve` handler returns an assembly with a manifest resource that is an assembly ref, we incorrectly resolved the reference on the original assembly instead of the assembly returned by the handler and then also looked for the resource on the original assembly again instead of using the referenced assembly. This change includes a test for this case using IL. The manifest resource file (as opposed to assembly ref) case is already covered in libraries tests.
- Loading branch information
1 parent
bbc02a5
commit 2a19c9d
Showing
6 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/tests/Loader/ResourceResolve/ManifestResourceAssemblyRef.il
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
.assembly extern System.Runtime | ||
{ | ||
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) | ||
} | ||
|
||
.assembly extern ResourceAssembly | ||
{ | ||
.publickeytoken = (00 00 00 00 00 00 00 00) | ||
} | ||
|
||
.assembly ManifestResourceAssemblyRef { } | ||
|
||
.mresource public 'MyResource' | ||
{ | ||
.assembly extern 'ResourceAssembly' | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/Loader/ResourceResolve/ManifestResourceAssemblyRef.ilproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.IL"> | ||
<PropertyGroup> | ||
<OutputType>library</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="ManifestResourceAssemblyRef.il" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<EmbeddedResource LogicalName="MyResource" Include="$(MSBuildProjectFile)" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using Xunit; | ||
|
||
[ConditionalClass(typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNotNativeAot))] | ||
public unsafe class ResourceResolve | ||
{ | ||
[Fact] | ||
[SkipOnMono("AssemblyRef manifest resource is not supported")] | ||
public static void AssemblyRef() | ||
{ | ||
string resourceName = "MyResource"; | ||
Assembly assembly = typeof(ResourceResolve).Assembly; | ||
|
||
// Manifest resource is not in the current assembly | ||
Stream stream = assembly.GetManifestResourceStream(resourceName); | ||
Assert.Null(stream); | ||
|
||
// Handler returns assembly with a manifest resource assembly ref that | ||
// points to another assembly with the resource | ||
ResolveEventHandler handler = (sender, args) => | ||
{ | ||
if (args.Name == resourceName && args.RequestingAssembly == assembly) | ||
return Assembly.Load("ManifestResourceAssemblyRef"); | ||
|
||
return null; | ||
}; | ||
AppDomain.CurrentDomain.ResourceResolve += handler; | ||
stream = assembly.GetManifestResourceStream(resourceName); | ||
AppDomain.CurrentDomain.ResourceResolve -= handler; | ||
Assert.NotNull(stream); | ||
|
||
// Verify that the stream matches the expected one in the resource assembly | ||
Assembly resourceAssembly = Assembly.Load("ResourceAssembly"); | ||
Stream expected = resourceAssembly.GetManifestResourceStream(resourceName); | ||
Assert.Equal(expected.Length, stream.Length); | ||
Span<byte> expectedBytes = new byte[expected.Length]; | ||
expected.Read(expectedBytes); | ||
Span<byte> streamBytes = new byte[stream.Length]; | ||
stream.Read(streamBytes); | ||
Assert.Equal(expectedBytes, streamBytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<Compile Include="ResourceResolve.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
<ProjectReference Include="ManifestResourceAssemblyRef.ilproj" /> | ||
<ProjectReference Include="ResourceAssembly.csproj" /> | ||
</ItemGroup> | ||
</Project> |