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

Use across assemblies that use [assembly: InternalsVisibleTo(...)] produces warnings #93

Closed
rickbrew opened this issue Dec 18, 2023 · 2 comments
Assignees

Comments

@rickbrew
Copy link

Let's say you have assembly A and assembly B, with B referencing A.

Assembly A declares [assembly: InternalsVisibleTo("B")]. Both assemblies make use of [AutoConstructor].

You'll get this warning when compiling assembly B:

warning CS0436: The type 'AutoConstructorAttribute' in 'AutoConstructor.Generator\AutoConstructor.Generator.AutoConstructorGenerator\AutoConstructorAttribute.cs' conflicts with the imported type 'AutoConstructorAttribute' in 'A, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'AutoConstructor.Generator\AutoConstructor.Generator.AutoConstructorGenerator\AutoConstructorAttribute.cs'.

I compile with warnings-as-errors so this actually prevents me from compiling. Thankfully you can suppress this warning, which also prevents it from turning into an error, via .editorconfig (or elsewhere) and then the compiler is happy:

# CS0436: Type conflicts with imported type
# Ensures that per-assembly source-generated attributes, e.g. [AutoConstructor], will not raise errors
dotnet_diagnostic.CS0436.severity = none

@Sergio0694 just fixed this exact issue in a new generator by emitting the suppression automatically and only for the type in question.

@k94ll13nn3 k94ll13nn3 self-assigned this Dec 18, 2023
@Sergio0694
Copy link
Contributor

@k94ll13nn3 if it helps, you should be able to pretty much just copy this, minus some tweaks 🙂

@k94ll13nn3
Copy link
Owner

Thanks for the report and for the sample code.
Fixed in 5.2.0, should be out on NuGet shortly.

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

3 participants