Circular dependency in generated code-behind
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: 5.0.100
* Windows version: Win10-x64
* Does the bug reproduce also in WPF for .NET Framework 4.8?: unknown
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)?: maybe, altho i think its more the code generation part.
**Problem description:**
Having two classes `A.B.C.D` and `A.B.C.A` where `A.B.C.D` is a WPF control and also inherits from `A.B.C.A` produces a circular dependency at compile time inside the generated files for the code-behind of `A.B.C.D`.
**Minimal repro:**
Recipes/UI/Pages/Recipes.xaml:
```xml
```
Recipes/UI/Pages/BaseDataGridControls.cs:
```csharp
namespace Recipes.UI.Pages {
public class BaseDataGridControls : Control { ... }
}
```
**Actual behavior:**
Recipes/UI/Pages/Recipes.xaml generates the following Recipes.g.cs :
```csharp
[...]
using Recipes.UI.Pages;
[...]
namespace Recipes.UI.Pages {
[...]
public partial class Recipes : Recipes.UI.Pages.BaseDataGridControls, System.Windows.Markup.IComponentConnector {
[...]
}
[...]
}
```
Which is a circular dependency, since the compiler interprets `Recipes.UI.Pages.BaseDataGridControls` as the class `Recipes`, and not as the namespace. Ironically, the generator also produces the include statement for the namespace, so if the namespace wasn't explicitly specified everything would be fine:
```csharp
[...]
using Recipes.UI.Pages;
[...]
namespace Recipes.UI.Pages {
[...]
//this would work
public partial class Recipes : BaseDataGridControls, System.Windows.Markup.IComponentConnector {
[...]
}
[...]
}
```
I am well aware that the explicit specification is done to avoid collisions that occur more often and this might just be a case of 'don't arrange you classes in this way', but maybe me having encountered the problem warrens the additional complexity in the code generator to detect this case.
Contributor guide
Assessment
This issue has not been assessed yet.