Use reflection-only context for InternalsVisibleToAttribute type comparison #4192
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.
Description
Use reflection-only context for InternalsVisibleToAttribute type comparison.
Fixes Issue #2492: Compilation error MC3064 when importing internal user control from signed class library. The wrong load context was used for a type comparison that always failed.
Customer Impact
Internal types contained in assemblies with InternalsVisibleTo attributes that are referenced in markup cause a markup compiler error: error MC3064: Only public or internal classes can be used within markup. 'InternalClass' type is not public or internal.
Regression
This is a regression from .NET Framework.
Testing
Repro'd the issue and tested the fix against .NET Core targeting .NET Framework 4.72/4.8 + .NET Core 3.1/6.0 and .NET Framework targeting .NET Framework 4.72/4.8 + .NET Core 3.1/6.0. Referencing internal types in markup that are contained in an assembly with InternalsVisibleTo (which grants access to the target assembly) now works as expected.