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

What's the purpose of adding TypeForwardedTo attributes? #90

Open
0xced opened this issue Nov 11, 2023 · 2 comments
Open

What's the purpose of adding TypeForwardedTo attributes? #90

0xced opened this issue Nov 11, 2023 · 2 comments

Comments

@0xced
Copy link
Contributor

0xced commented Nov 11, 2023

In #86 you said

generate type forwards to ensure things work as expected in multi-targeting scenarios

Could you please elaborate a little bit more on this? What exact problem does it solve to add TypeForwardedTo attributes in target frameworks where the type exists?

For example, when multi-targeting net7.0;net6.0;netstandard2.0 the source generator produces this for .NET 6 and .NET 7 targets:

[assembly: global::System.Runtime.CompilerServices.TypeForwardedTo(typeof(global::System.Runtime.CompilerServices.IsExternalInit))]

If I add <PolySharpExcludeTypeForwardedToDeclarations>true</PolySharpExcludeTypeForwardedToDeclarations> they are not generated and everything seems to work fine. Am I missing something?

@OwnageIsMagic
Copy link

OwnageIsMagic commented Nov 13, 2023

In case you generate attributes as public in lib A and have reference to them in another lib B (or generate as internal and use reflection).
With this attribute lib A will always have definition of IsExternalInitAttribute (real or forwarded). Without it, there is a possibility of TypeLoadException in some edge cases if A and B are updated separately, but I wold say in any sane deploy scheme this should not be a problem. Or maybe I missing something obvious.

@OwnageIsMagic
Copy link

Like if you publish lib A ver 1, but in ver 2 change PolySharp settings, so this type is no longer generated.
Lib B is transitive dep of app have dependency on A.v1, and app have direct dep on lib A.v2 -- assembly redirection would kick in and choose A.v2 and lib B will throw TypeLoadException.

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