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

Can't resolve custom attributes outside of the target assembly #2

Open
asklar opened this issue Jan 23, 2021 · 1 comment
Open

Can't resolve custom attributes outside of the target assembly #2

asklar opened this issue Jan 23, 2021 · 1 comment

Comments

@asklar
Copy link
Contributor

asklar commented Jan 23, 2021

I have a type/method that I've added [deprecated("foo", deprecate, 1)] to.

ca.GetArguments(out var fixedArgs, out var namedArgs);

both argument lists are empty, because it's trying to resolve the custom attribute in the same Assembly where it is applied to.

The code correctly identifies the need to resolve DeprecationType in the Windows.FoundationContract assembly, but this is marked as a fake assembly, so it calls RaiseFakeTypeRequired, but the FakeTypeRequired event handler is null.

Update:
The solution is to do something like:

            context.FakeTypeRequired += (sender, e) => {
                var ctx = sender as MrLoadContext;
                if (e.AssemblyName == "Windows.Foundation.FoundationContract")
                {
                    e.ReplacementType = ctx.GetTypeFromAssembly(e.TypeName, "Windows");
                }
            };

This should probably be a default though, or at least documented :)

@MikeHillberg
Copy link
Owner

Attributes outside of the target assembly should be OK, but I don't think there's a way to make this work with a fake type. At least when there's an enum involved, it's necessary to know the type information so that the metadata reader understands the binary layout in the file.

(Error shows up here, fallback code for attributes is here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants