英文:
How can I resolve false error messages in Visual Studio for a Blazor Server Side project?
问题
Visual Studio中的虚假错误消息问题,需要帮助
大家好,
我在Visual Studio中遇到了一个奇怪的问题,我看到了实际上并不存在的错误消息。虽然我仍然能够构建项目而没有任何问题,但这些虚假的错误消息却在造成阻碍。一个具体的错误出现在文件Authorize.razor
中的一行" @typeparam T_User where T_User: IdentityUser<Guid>, IUser
",在项目*...*的Security
中,我在" where
"关键字处收到了一个RZ1017
错误。我真的不知道为什么。在另一个项目的另一个.razor文件中,它正常工作。奇怪的是,这个错误也存在于解决方案中的另一个项目中,但在这种情况下,它阻止了成功的构建。
我想指出的是,这个问题在三个小时前还不存在。它似乎突然出现,没有对代码或项目设置进行任何更改。
以下是我已经尝试解决这个问题的步骤:
1. 关闭Visual Studio中的所有文档。
2. 多次重启Visual Studio。
3. 删除"bin"和"obj"文件夹。
4. 清除Roslyn缓存。
5. 清除ComponentModel缓存。
6. 删除".vs"文件夹。
7. 再次克隆存储库。
8. 重启电脑。
9. 使用Visual Studio Installer来"修复"Visual Studio。
这是存储库的链接:https://github.com/NicoVolling/NicoVolling-Web
Visual Studio版本: Community Edition 2022 17.6.0
项目详情: .NET 7, Asp.NET, Blazor Server Side, Entity Framework, Identity
Security项目中的Authorize.razor:
@using Microsoft.AspNetCore.Identity;
@using NiVo.Framework.Components;
@using NiVo.Framework.Security.Authorization;
@using NiVo.Framework.Security.Identity;
@inherits BaseComponent
@typeparam T_User where T_User : IdentityUser<Guid>, IUser
@typeparam T_LoginPage
@typeparam T_404Page
@if (Display && ChildContent != null)
{
@ChildContent(User)
}
else if(ShowLoginIfNotAuthorized && !ValidateAsync(BaseRules.Authenticated).Result)
{
<DynamicComponent Type="typeof(T_LoginPage)" Parameters="@(new Dictionary<string, object>() { { "ReturnUrl", NavigationManager.Uri.Replace(NavigationManager.BaseUri, "") } })" />
}
else if(Show404NotAuthorized)
{
<DynamicComponent Type="typeof(T_404Page)" />
}
Security项目中的Security.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NiVo.Framework.Components\NiVo.Framework.Components.csproj" />
<ProjectReference Include="..\NiVo.Framework.Data\NiVo.Framework.Data.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
如果有人遇到类似的问题或有任何解决此问题的建议,我将非常感激您的帮助。请让我知道是否需要进一步的信息。
提前感谢您!
Nico Volling
编辑 #1:
我在Windows 11 Dev VM中尝试了Visual Studio Community Edition 2022 17.5.5:工作正常。我不知道它是否依赖于设置、版本或其他什么。下一步:我正在更新VM中的VS。如果问题出现,那么它是一个版本问题。
编辑 #2:
这是一个版本问题。刚刚升级到版本17.6:几乎一切都不好!
所以我需要回到版本17.5.5或17.5.IDontKnow
编辑 #3:
在版本17.6.2中,此问题仍然存在。
编辑 #4:
在版本17.6.3中,此问题仍然存在。
英文:
Issue with false error messages in Visual Studio, help needed
Hello everyone,
I'm experiencing a peculiar issue in Visual Studio where I'm seeing error messages that do not actually exist. While I am still able to build the project without any problems, these false errors are causing hindrances. One specific error is occurring in the line "@typeparam T_User where T_User: IdentityUser<Guid>, IUser
" in file Authorize.razor
in project ...Security
where I'm getting an RZ1017
error at the "where
" keyword. I really don't know why. In another project another .razor file it works fine. The strange thing is that this error is also present in another project within the solution, but in that case, it prevents successful builds.
I want to note that this problem was not present three hours ago. It seems to have occurred suddenly without any changes made to the code or project settings.
Here are the steps I've already tried to resolve the issue:
1. Closed all documents in Visual Studio.
2. Restarted Visual Studio multiple times.
3. Deleted the "bin" and "obj" folders.
4. Cleared the Roslyn cache.
5. Cleared the ComponentModel cache.
6. Deleted the ".vs" folder.
7. Cloned the repository again.
8. Restarted the PC.
9. Used the Visual Studio Installer to "Repair" Visual Studio
Here's the link to the repository: https://github.com/NicoVolling/NicoVolling-Web
Visual Studio Version: Community Edition 2022 17.6.0
Project Details: .NET 7, Asp.NET, Blazor Server Side, Entity Framework, Identity
Authorize.razor from Security Project:
@using Microsoft.AspNetCore.Identity;
@using NiVo.Framework.Components;
@using NiVo.Framework.Security.Authorization;
@using NiVo.Framework.Security.Identity;
@inherits BaseComponent
@typeparam T_User where T_User : IdentityUser<Guid>, IUser
@typeparam T_LoginPage
@typeparam T_404Page
@if (Display && ChildContent != null)
{
@ChildContent(User)
}
else if(ShowLoginIfNotAuthorized && !ValidateAsync(BaseRules.Authenticated).Result)
{
<DynamicComponent Type="typeof(T_LoginPage)" Parameters="@(new Dictionary<string, object>() { { "ReturnUrl", NavigationManager.Uri.Replace(NavigationManager.BaseUri, "") } })" />
}
else if(Show404NotAuthorized)
{
<DynamicComponent Type="typeof(T_404Page)" />
}
Screenshot: Errors in File Authorize.razor
Security.csproj from Security Project:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NiVo.Framework.Components\NiVo.Framework.Components.csproj" />
<ProjectReference Include="..\NiVo.Framework.Data\NiVo.Framework.Data.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
If anyone has encountered a similar problem or has any suggestions on how to resolve this issue, I would greatly appreciate your help. Please let me know if you need any further information.
Thank you in advance!
Nico Volling
EDIT #1:
I tried in a Windows 11 Dev VM with Visual Studio Community Edition 2022 17.5.5: Works fine. I don't know if it depends on Settings, Version or something else. Next Step: I'm currently updating VS in the VM. If the problem appears, then its a version problem.
EDIT #2:
Its a version problem. Just upgraded to version 17.6: literally nothing is fine!
So i need to go back to Version 17.5.5 or 17.5.IDontKnow
EDIT #3:
This Issue still exists in version 17.6.2.
EDIT #4:
This Issue still exists in version 17.6.3
答案1
得分: 1
A possible workaround to my problem was to roll back from Visual Studio Version 17.6.
See Edit #2 of my Question:
> Its a version problem. Just upgraded to version 17.6: literally
> nothing is fine! So i need to go back to Version 17.5.5 or
> 17.5.IDontKnow
So this is the complete answer to my question.
Edit #1:
Found a better workaround: i created a global.json in the solution folder (or above):
{
"sdk": {
"version":"7.0.202"
}
}
This forces Visual Studio to use the old compiler, so you can use Visual Studio 17.6.3.
Edit #2:
Removing where-Satements from generic Blazor-Components is also a workaround.
英文:
A possible workaround to my problem was to roll back from Visual Studio Version 17.6.
See Edit #2 of my Question:
> Its a version problem. Just upgraded to version 17.6: literally
> nothing is fine! So i need to go back to Version 17.5.5 or
> 17.5.IDontKnow
So this is the complete answer to my question.
Edit #1:
Found a better workaround: i created a global.json in the solution folder (or above):
{
"sdk": {
"version":"7.0.202"
}
}
This forces Visual Studio to use the old compiler, so you can use Visual Studio 17.6.3.
Edit #2:
Removing where-Satements from generic Blazor-Components is also a workaround.
答案2
得分: 1
发现了一个解决方案,只需编辑包含Razor页面的**.csproj**文件,然后保存。
在Visual Studio启动并重新加载正确的Razor语言版本后,更新csproj文件会导致编辑器能够识别语法@typeparam T_User where T_User : IdentityUser<Guid>, IUser
。
每次加载解决方案时都需要这样做,等待下一个Visual Studio版本(现在是17.0.0)中修复此问题。
英文:
Found a solution, just edit the .csproj that contains razor pages, and save it.
Updating the csproj after Visual Studio has started reloading the correct Razor language version, and it results in having the syntax @typeparam T_User where T_User : IdentityUser<Guid>, IUser
to be recognized in the editor.
You have to do it each time the solution is loaded, waiting for the fix in the next Visual Studio version (now 17.0.0).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论