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

CS0436 (duplicate type) when using InternalsVisibleTo and project references #64

Closed
joelverhagen opened this issue Nov 18, 2024 · 2 comments · Fixed by #71
Closed

CS0436 (duplicate type) when using InternalsVisibleTo and project references #64

joelverhagen opened this issue Nov 18, 2024 · 2 comments · Fixed by #71
Milestone

Comments

@joelverhagen
Copy link

joelverhagen commented Nov 18, 2024

Suppose project ConsoleApp2 depends on project ConsoleApp1
Project ConsoleApp1 depends on PolyType.
Project ConsoleApp1 has [assembly:InternalsVisibleTo("ConsoleApp2")].

This means the following type is duplicate in ConsoleApp2's build:

namespace PolyType.SourceGenerator
{
    /// <summary>The source generated <see cref="global::PolyType.ITypeShapeProvider"/> implementation for the current assembly.</summary>
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("PolyType.SourceGenerator.PolyTypeGenerator", "0.18.1+5e98a961a4")]
    internal sealed partial class ShapeProvider
    {
        private const global::System.Reflection.BindingFlags __BindingFlags_Instance_All = 
            global::System.Reflection.BindingFlags.Public | 
            global::System.Reflection.BindingFlags.NonPublic | 
            global::System.Reflection.BindingFlags.Instance;
        
        /// <summary>Gets the default instance of the <see cref="ShapeProvider"/> class.</summary>
        public static ShapeProvider Default { get; } = new();
        
        /// <summary>Initializes a new instance of the <see cref="ShapeProvider"/> class.</summary>
        private ShapeProvider() { }
    }
}

Love the look of the project BTW! I have been building my own CSV and Kusto source generator from POCO for a while. This might be a fun project to simplify with.

@eiriktsarpalis
Copy link
Owner

Great to hear that you like it!

What solution would you recommend? It is conceivable that the generator could just suffix the class name with an identifier deriving from the name of the assembly, but I'm wondering if there's a better way.

@joelverhagen
Copy link
Author

joelverhagen commented Nov 18, 2024

I can think of three options:

  1. Disambiguate the name automatically or by configuration (as you stated)
  2. Add a hook to allow assembly aliasing. Seems like a pain and may not even work for project reference (never tried).
  3. Not sure of feasibility -- but could ConsoleApp2 re-use ConsoleApp1's implementation?

I am not sure if existing users of the library expect the shape provider to be called ShapeProvider. If so, option 1 would need to be opt-in (or enabled only when InternalsVisibleTo is detected).

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

Successfully merging a pull request may close this issue.

2 participants