-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Preserve invalid friend assembly error #127180
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80302f4
Initial plan
Copilot 6e589e5
Preserve invalid friend assembly diagnostics by removing lossy HRESUL…
Copilot 6ab5020
Preserve invalid friend assembly name as inner exception
elinor-fung b3bc5b1
Explain how the test triggers InternalsVisibleTo parsing
elinor-fung 72ff462
Restrict InvalidFriendAssemblyName test to CoreCLR
elinor-fung 8739b07
Skip InvalidFriendAssemblyName test on Mono and NativeAOT
elinor-fung c6094e7
Rethrow transient exceptions instead of wrapping invalid friend name
elinor-fung 33bf728
Potential fix for pull request finding
elinor-fung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
...sts/Loader/classloader/regressions/InvalidFriendAssemblyName/InvalidFriendAssemblyName.cs
This file contains hidden or 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,34 @@ | ||
| // 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.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| [assembly: InternalsVisibleTo(InvalidFriendAssemblyName.InvalidAssemblyName)] | ||
|
|
||
| public class InvalidFriendAssemblyName | ||
| { | ||
| internal const string InvalidAssemblyName = "Broken,PublicKey=00240000048000009400000006020000002400005253413100040000010001002d07581667cbf8caf9786ac8d5257eb2c77eb2643a1af1bb89d4286e27a3ff5d805408c9f1a0a392d2f478ca2b9c68e43cdcdcea2d7cf0618dd8ba48858bf5fc74c7fc2af7a29f936398c0f61a2165d08ac4fcc8e8ad04e24633b7ca31a7c13f750ae75e53cea55ced97d3289fd100dbe2661a802bf8bd2acb0b6893ef3fb79c,PublicKeyToken=282361b99ded7e8e"; | ||
|
|
||
| // Only CoreCLR surfaces the invalid friend name as a FileLoadException. | ||
| [ConditionalFact(typeof(TestLibrary.Utilities), nameof(TestLibrary.Utilities.IsNotMonoRuntime), nameof(TestLibrary.Utilities.IsNotNativeAot))] | ||
| public static void TestEntryPoint() | ||
| { | ||
| // Calling the protected Object.MemberwiseClone (defined in a different assembly) forces the | ||
| // runtime to run an accessibility check against this assembly, which parses its InternalsVisibleTo | ||
| // metadata. Because that metadata is invalid, parsing throws and surfaces the FileLoadException. | ||
| FileLoadException exception = Assert.Throws<FileLoadException>(() => new InvalidFriendAssemblyName().GetCopy()); | ||
|
elinor-fung marked this conversation as resolved.
|
||
|
|
||
|
elinor-fung marked this conversation as resolved.
elinor-fung marked this conversation as resolved.
|
||
| // The outer exception identifies the assembly that declared the invalid friend reference. | ||
| Assert.Contains(nameof(InvalidFriendAssemblyName), exception.FileName, StringComparison.Ordinal); | ||
|
|
||
| // The inner exception preserves the real cause: the invalid friend assembly name. | ||
| FileLoadException inner = Assert.IsType<FileLoadException>(exception.InnerException); | ||
| Assert.Equal(InvalidAssemblyName, inner.FileName); | ||
| Assert.Contains("assembly name was invalid", inner.Message, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| public object GetCopy() => MemberwiseClone(); | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
...Loader/classloader/regressions/InvalidFriendAssemblyName/InvalidFriendAssemblyName.csproj
This file contains hidden or 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,6 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <ItemGroup> | ||
| <Compile Include="InvalidFriendAssemblyName.cs" /> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.