開發(fā)環(huán)境
C#開發(fā)環(huán)境Visual Studio 2022 V17.6.2版本。
目標框架:
.NET 6.0文章來源:http://www.zghlxwxcb.cn/news/detail-474503.html
錯誤內容:
系統(tǒng)是Blazor Server框架的系統(tǒng)頁面,在使用Visual Studio 2022 V17.6.2版本編譯后,執(zhí)行出現:文章來源地址http://www.zghlxwxcb.cn/news/detail-474503.html
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)
問題分析過程:
- 先使用了Visual Studio 2022 V17.4.0版本編譯后可以正常。
- 經過分析:Visual Studio 2022 V17.4.0還在使用的目標框架為:.NET 6.0,Visual Studio 2022 V17.6.2版本的目標框架為:.NET 7.0
- 首先懷疑目標框架為:.NET 7.0造成的不兼容的問題,嘗試System.Private.CoreLib.dll的NET6.0版本。直接放在系統(tǒng)執(zhí)行環(huán)境中,嘗試是否可以正常使用,結果:失敗。
- 再次嘗試,安裝Visual Studio 2022舊版本,因為在官方網站上下載的Visual Studio 2022都是最新版本。下載地址:下載 Visual Studio Tools - 免費安裝 Windows、Mac、Linux (microsoft.com),Visual Studio 2022 分3類版本:社區(qū)版、個人版、企業(yè)版;大家可以根據自己需求選則下載,此處連接下載的都是最新版本。
- 在官方網站中查找VS2022的歷史版本:Visual Studio 2022 發(fā)行歷史記錄 | Microsoft Learn,以下內容可以選擇自己的版本,經過測試:17.2版本支持最新的.NET6.0框架,17.4.1版本以后就支持.NET7.0框架。下載17.2版本中的最新版本:17.2.15版本。
- 經過測試,Visual Studio 2022 V17.2.15版本,編譯后的程序可以正常使用。
- 通過其他人員安裝的不同版本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 | 正常 |
總結:
- 通過測試發(fā)現,出現問題應該和VS2022的版本有關,和NET7.0環(huán)境無關。希望Visual Studio 2022新版本可以解決此BUG吧!
- 建議:不要盲目的追求使用最新版本的Visual Studio,特別是生產型企業(yè),這樣會導致生產停線,造成的損失就比較大了。
- 官網網站上針對舊版的引導程序(引導程序安裝必須有外部網絡),提供了“結束支持日期”,害怕結束支持日期一到,引導程序就無法在線安裝(我理解的這個不知對不對?。。。?。接著研究一下怎么把歷史版本保留下來,以后安裝時可以通過本地文件直接安裝。
到了這里,關于記錄一次.NET6環(huán)境使用Visual Studio 2022 V17.6.2版本的異常的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!