记录一次.NET6环境使用Visual Studio 2022 V17.6.2版本的异常

  • 记录一次.NET6环境使用Visual Studio 2022 V17.6.2版本的异常已关闭评论
  • 102 次浏览
  • A+
所属分类:.NET技术
摘要

C#开发环境Visual Studio 2022 V17.6.2版本。.NET 6.0系统是Blazor Server框架的系统页面,在使用Visual Studio 2022 V17.6.2版本编译后,执行出现:


开发环境

C#开发环境Visual Studio 2022 V17.6.2版本。

目标框架:

.NET 6.0

错误内容:

系统是Blazor Server框架的系统页面,在使用Visual Studio 2022 V17.6.2版本编译后,执行出现:

TimeStamp: 2023/6/6 13:35:07 MachineName: Light.Yang AppDomainName: SajetServerApp OS: Microsoft Windows 10.0.18363 OSArchitecture: X64 ProcessArchitecture: X64 Framework: .NET 6.0.16 UserName: lukel VSIDE: Microsoft Visual Studio Community 2022 17.0  Message: Unable to set property 'placeholder' on object of type 'Sajet.WebUI.Components.SelectInput`1[[System.String,System.Private.CoreLib,Version=6.0.0.0, Culture=neutral,PublicKeyToken=7cec85d7dea7798e]]'.The error  was: Unable to cast object of type 'MicrosoftExtensions.Localization.localizedString' to type 'System.Strinq'. ********************************************** StackTrace: at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.g_SetProperty|3_0(Object target,PropertySetter writer,String parameterName,Object value) at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Obiect target) at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target) at BootstrapBlazor.Components.ValidateBase`1.SetParametersAsync(ParameterView parameters) at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)  

问题分析过程:

  1. 先使用了Visual Studio 2022 V17.4.0版本编译后可以正常。
  2. 经过分析:Visual Studio 2022 V17.4.0还在使用的目标框架为:.NET 6.0,Visual Studio 2022 V17.6.2版本的目标框架为:.NET 7.0
  3. 首先怀疑目标框架为:.NET 7.0造成的不兼容的问题,尝试System.Private.CoreLib.dll的NET6.0版本。直接放在系统执行环境中,尝试是否可以正常使用,结果:失败。
  4. 再次尝试,安装Visual Studio 2022旧版本,因为在官方网站上下载的Visual Studio 2022都是最新版本。下载地址:下载 Visual Studio Tools - 免费安装 Windows、Mac、Linux (microsoft.com),Visual Studio 2022 分3类版本:社区版、个人版、企业版;大家可以根据自己需求选则下载,此处连接下载的都是最新版本。
  5. 在官方网站中查找VS2022的历史版本:Visual Studio 2022 发行历史记录 | Microsoft Learn,以下内容可以选择自己的版本,经过测试:17.2版本支持最新的.NET6.0框架,17.4.1版本以后就支持.NET7.0框架。下载17.2版本中的最新版本:17.2.15版本。
    记录一次.NET6环境使用Visual Studio 2022 V17.6.2版本的异常
  6. 经过测试,Visual Studio 2022 V17.2.15版本,编译后的程序可以正常使用。
  7. 通过其他人员安装的不同版本VS2022进行测试结果如下
VS 2022版本 支持最新框架 测试结果
Visual Studio 2022 V17.6.2 .NET6.0 出现异常
Visual Studio 2022 V17.5.2 .NET7.0 正常
Visual Studio 2022 V17.4.0 .NET6.0 正常
Visual Studio 2022 V17.2.15 .NET6.0 正常

总结:

  1. 通过测试发现,出现问题应该和VS2022的版本有关,和NET7.0环境无关。希望Visual Studio 2022新版本可以解决此BUG吧!
  2. 建议:不要盲目的追求使用最新版本的Visual Studio,特别是生产型企业,这样会导致生产停线,造成的损失就比较大了。
  3. 官网网站上针对旧版的引导程序(引导程序安装必须有外部网络),提供了“结束支持日期”,害怕结束支持日期一到,引导程序就无法在线安装(我理解的这个不知对不对!!!)。接着研究一下怎么把历史版本保留下来,以后安装时可以通过本地文件直接安装。