我正在使用 WinUI 3.0 在 C# 中制作一个 UWP Windows 应用程序,几天前我开始遇到这种错误:
CS0433 The type 'NavigationView' exists in both 'Microsoft.UI.Xaml, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' and 'Microsoft.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'
这是导致错误的自动生成代码的片段:
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 0.0.0.0")]
private global::Microsoft.UI.Xaml.Controls.NavigationView settingsNavPane;
到目前为止,我通过删除
/bin
和/obj
的内容解决了这个问题,但问题似乎仍然存在。
我知道这是一个编译器错误,所以我尝试添加对 .csproj 文件的引用:
<References>
<Reference Include="Microsoft.UI.Xaml.dll"/>
</References>
我不知道我是否遗漏了一些明显的东西,但这也没有解决问题。我该如何解决这个问题?
从你的错误中得出,看起来你没有具体的
XamlControlsResources
,请参考这个document并在你的app.xaml文件中添加XamlControlsResources。
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
问题是 Microsoft.EntityFrameworkCore.SqlServer 版本 7 及更高版本后会产生此问题。将版本降级到 6.014 为我解决了这个问题。