WinForms Designer fails when `.resx` files are also included as `AdditionalFiles`
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### Environment
18.9.1
### .NET version
.NET 10
### Did this work in a previous version of Visual Studio and/or previous .NET release?
Do not know.
### Issue description
The WinForms designer for a .NET 10 project fails to open a form when the form's .resx file is also included as an analyzer AdditionalFiles item.
It either displays "Method not supported" in a plain message box:
Sometimes it does display the designer tab, but with this error: "IntelliSense finished initializing, but an error occurred when attempting to load the document" and the error code 0x80131515.
I cannot tell when which happens, but I've seen both.
Attaching a debugger to the relevant Visual Studio/designer process and breaking on thrown System.NotSupportedException leads to the project-system implementation of FileProperties.BuildAction.
The implementation effectively performs:
```
string itemType = FileProperties2.ItemType;
switch (itemType)
{
case "Content":
case "Compile":
case "EmbeddedResource":
case "None":
// map to EnvDTE.prjBuildAction
break;
default:
throw new NotSupportedException();
}
```
AdditionalFiles cannot be represented by the old EnvDTE.prjBuildAction enum.
This appears to become problematic when a physical .resx file is represented by both:
`EmbeddedResource`
and:
`AdditionalFiles`
and the WinForms designer/project-system code subsequently requests its BuildAction.
In my case, it is present in AdditionalFiles, because I have a Code Analyzer that checks for string resource issues and thus needs .resx files to be exposed as additional files.
### Steps to reproduce
Add a normal WinForms form, for example:
- Form1.cs
- Form1.Designer.cs
- Form1.resx
Verify that Form1 opens normally in the WinForms designer.
Then modify the project so that .resx files are also analyzer additional files:
```
```
The complete project can therefore be as simple as:
```
WinExe
net10.0-windows
true
enable
enable
```
Close and reopen Form1 in the designer.
### Diagnostics
```text
The "Windows Forms" output pane only shows these messages:
[13:31:46.794450] info: Added 'mscorlib'
[13:31:46.799449] trce: Processed 'System.Windows.Forms' in 00:00:00.0050416
[13:31:46.819450] info: Creating VsDesignerLoader
[13:31:46.821449] info: Added 'System.Windows.Forms'
[13:31:46.822448] trce: Processed 'System' in 00:00:00.0014729
[13:31:46.844460] info: Added 'System'
[13:31:46.844460] trce: Processed 'System.Drawing' in 00:00:00.0001542
[13:31:46.846461] info: Added 'System.Drawing'
[13:31:46.863979] trce: Processed 'System.Design' in 00:00:00.0169381
[13:31:46.879977] info: Added 'System.Design'
[13:31:46.880977] trce: Processed 'System.Drawing.Design' in 00:00:00.0002810
[13:31:46.880977] info: Added 'System.Drawing.Design'
```
Contributor guide
Research direction
Reproduce the failure with the minimal WinForms project and the AdditionalFiles glob shown in the issue. Then inspect the project-system implementation of FileProperties.BuildAction and FileProperties2.ItemType, focusing on how a .resx represented as both EmbeddedResource and AdditionalFiles is handled. Done means the form opens normally in the WinForms designer without either reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100