Skip to content

Commit

Permalink
[custom_attrs] Use the image's ALC instead of the default one (dotnet…
Browse files Browse the repository at this point in the history
…#68266)

Running ApiCompat task under Mono fails with:

    Could not load type System.Collections.Generic.IEqualityComparer`1[[Microsoft.Cci.ITypeReference, Microsoft.Cci ...

The reason is that cattr_type_from_name() uses a default ACL instead of
the image's one. This is important, because ExportCciSettings.Settings
field has the

      [Export(typeof(IEqualityComparer<ITypeReference>))]

custom attribute [1], where ITypeReference comes from the Microsoft.Cci
assembly. ApiCompat task runs under MSBuild, which provides its own
MSBuildLoadContext ALC. Microsoft.Cci is supposed to be found using
this ALC, not the default one.

[1] https://github.com/dotnet/arcade/blob/8f311fed1f2acf0ecfdfcecbc7a9fa871ed634cc/src/Microsoft.DotNet.ApiCompat/src/Microsoft.DotNet.ApiCompat.Core/ExportCciSettings.cs#L28
  • Loading branch information
iii-i committed Jun 7, 2022
1 parent 0712aeb commit 8013185
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/custom-attrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static MonoType*
cattr_type_from_name (char *n, MonoImage *image, gboolean is_enum, MonoError *error)
{
ERROR_DECL (inner_error);
MonoAssemblyLoadContext *alc = mono_alc_get_ambient ();
MonoAssemblyLoadContext *alc = mono_image_get_alc (image);
MonoType *t = mono_reflection_type_from_name_checked (n, alc, image, inner_error);
if (!t) {
mono_error_set_type_load_name (error, g_strdup(n), NULL,
Expand Down

0 comments on commit 8013185

Please sign in to comment.