reactiveui / ReactiveUI.SourceGenerators

Use source generators to generate objects.
MIT License
31 stars 3 forks source link

[Bug]: Error with Source Generator when using multiple types with the same name in different namespaces #131

Closed Soar360 closed 2 weeks ago

Soar360 commented 2 weeks ago

Describe the bug 🐞

I'm encountering an issue with the ReactiveUI.SourceGenerators package (version 2.0.17) in my Avalonia project. After upgrading to this version, I receive the following warning during compilation:

warning CS8785: The generator "ReactiveGenerator" failed to produce source. This will not affect the output, but may cause compilation errors. The exception type is "ArgumentException", with the message "The hintName 'SearchTask' was added by source file, but the two types exist in different namespaces. .Properties.g.cs must be unique within the generator." (Parameter 'hintName')

This issue arises because I have two SearchTask types in my project, but they are in different namespaces. It seems that the generator is having trouble handling multiple types with the same name but different namespaces.

I would like to request that this issue be addressed in the official ReactiveUI repository, as it currently prevents me from using the Source Generators effectively.

Step to reproduce

  1. Create two types with the same name (e.g., SearchTask) in different namespaces.
  2. Upgrade to ReactiveUI.SourceGenerators version 2.0.17.
  3. Compile the project and observe the error.

Reproduction repository

https://github.com/reactiveui/ReactiveUI.SourceGenerators

Expected behavior

The source generator should handle cases where multiple types share the same name but are in different namespaces without causing conflicts or errors.

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows

Version

2.0.17

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

glennawatson commented 2 weeks ago

Can you provide a small source code snippet if able of a class that's producing the error?

We will use it in our unit tests.

Cheers

Soar360 commented 2 weeks ago

Try this:

https://github.com/Soar360/ReactiveUI.SourceGenerators.Fix131

image

CSC: warning CS8785: The generator "ReactiveGenerator" failed to generate source. It will not affect output, but it may cause compilation errors. The exception type is "ArgumentException" with the message "The hintName 'SearchTask.Properties.g.cs' of the added source file must be unique within the generator. (Parameter 'hintName')".

and

D:\src\test\ReactiveUI.SourceGenerators.Fix131\Demo\Demo>dotnet --list-sdks
6.0.100 [C:\Program Files\dotnet\sdk]
8.0.404 [C:\Program Files\dotnet\sdk]
9.0.100 [C:\Program Files\dotnet\sdk]
GitHub
GitHub - Soar360/ReactiveUI.SourceGenerators.Fix131
Contribute to Soar360/ReactiveUI.SourceGenerators.Fix131 development by creating an account on GitHub.
glennawatson commented 2 weeks ago

Appreciate it. We should have a fix out for this weekend.