[BUG] Objects defined in XAML are shown as undefined in code behind
Describe the Issue
After upgrading the extension, objects defined in XAML via x:Name and also the InitializeComponent() method are shown as undefined in code behind.
Steps To Reproduce
- Open a WindowsAppSDK project code behind file
- Observe the shown errors
Expected Behavior
Objects defined in XAML should be detected as defined in code behind
Environment Information
-Windows 11 -VSCode 1.78.2 -C# extension v2.0.206
Can reproduce on not just WinUI and/or WPF, but also Avalonia. This seems to stem from the new LSP not being able to run any source generator. Smallest repro I can think of is using CommunityToolkit.Mvvm
using CommunityToolkit.Mvvm;
namespace SourceGenRepro;
public partial class SomeObject : ObservableObject
{
[ObservableProperty]
private string _name = "Something";
public SomeObject()
{
Console.WriteLine(Name);
}
}
This incorrectly causes a CS0103 Roslyn diagnostic.
I believe I'm running into a similar issue with Godot.
[Signal]
public delegate void EnemySpawnedEventHandler(Enemy enemy);
protected void OnEnemySpawned(object sender, EnemyEventArgs e)
{
EmitSignal(SignalName.EnemySpawned, e.Enemy);
}
This causes CS0117 at SignalName.EnemySpawned which should exist but it doesn't.
I'm having the same issue with Godot 4 on Ubuntu 23.04.
Godot's source generators add code to complete my partial class definitions, but after updating the C# extension (and .NET 6 to 7), it won't recognize the generated code, and I get the same Roslyn(CS0117) error like above, when I use a generated member.
The error is on the IDE only; dotnet build works fine with no errors.
See also: #5999 and godotengine/godot-csharp-vscode#57
As a temporary workaround, you can tell C# extension to use Omnisharp instead of Roslyn with
"dotnet.server.useOmnisharp": trueinsettings.jsonand get proper support to generated code.
Closing - I believe this issue is fixed with the latest versions of the C# extension. If not, please open a new log with detailed repro steps and C# output window logs. Thanks!
This bug is not fixed even with the newest extension. Repro steps as described in the original bug report:
-Open a WinAppSDK project (e.g. create a new one in Visual Studio) -Open the folder in vscode
Output:
Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\4a71d6db"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info - 8:16:39 PM] [Program] Language server initialized
[Info - 8:16:41 PM] [WorkspaceProjectFactoryService] Project C:\Users\XXX\Source\Repos\App1\App1.csproj loaded by C# Dev Kit
Bug appears to still be going on, with the same description as originally described. However, I have found that the solution in this post post fixes the issue right away. Edit csproj file, rebuild, no more undefined objects in the code behind. What is most perplexing to me, however, is that if you revert the csproj change the issue does not come back.