Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Generator fails with identical view class names in different files #92

Closed
tristanlabelle opened this issue Nov 2, 2022 · 1 comment
Closed

Comments

@tristanlabelle
Copy link

I'm using a slightly unusual file organization for my UI with:

FooPage/
  View.axaml
  ViewModel.cs
BarPage/
  View.axaml
  ViewModel.cs

However, this fails to compile with:

Error	AXN0002	System.ArgumentException: The hintName 'View.g.cs' of the added source file must be unique within a generator.
Parameter name: hintName
   at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source)
   at Avalonia.NameGenerator.AvaloniaNameSourceGenerator.Execute(GeneratorExecutionContext context)

This is a limitation of Microsoft.CodeAnalysis.GeneratorExecutionContext.AddSource hit by this code:

var query =
from view in resolveViews
let names = _names.ResolveNames(view.Xaml)
let code = _code.GenerateCode(view.ClassName, view.Namespace, view.XamlType, names)
let fileName = $"{view.ClassName}.g.cs"
select new GeneratedPartialClass(fileName, code);

Would it be possible to include the full namespace in the generated source file name, ie FooPage.View.g.cs vs BarPage.View.g.cs? This should guarantee uniqueness.

@worldbeater
Copy link
Collaborator

worldbeater commented Nov 4, 2022

Thanks for reporting. Going to 🚢 the fix soon, hope our CD pipeline is still alive.
UPD Shipped as 1.4.1.

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

No branches or pull requests

2 participants