2023年12月7日 星期四

.Net Framewok 4.8 遇到System.IO.FileLoadException 無法載入檔案或組件 System.Resources.Extensions 0x80131040

為了sonarque可以跑在.net framework 4.8 WinForm的程式用了nuget 加了 System.Resources.Extensions 這個元件 然後終於可以跑了但是
建置時都正常

但是在runtime的時候出現以下錯誤的exception 
System.IO.FileLoadException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089無法載入檔案或組件 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 或其相依性的其中之一。 找到的組件資訊清單定義與組件參考不符。 (發生例外狀況於 HRESULT: 0x80131040)





上網google 都找不到什麼東西


後來發現解法就是需要再project 的加上<GenerateResourceUsePreserializedResources>True</GenerateResourceUsePreserializedResources 然後在app.config 加上 以下程式碼 看你裝的是8.0.0.0就newVersion就是8.0.0.0

然後就可以跑了 記錄一下

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="System.Resources.Extensions" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51" />

<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="8.0.0.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>




2022年9月23日 星期五

ASP.NET Core jQuery AJAX 回應出現400

在寫jQuery 的AJAX 的時候 response 給我400 參數也都對就是進不到controller的程式碼

上網照了一下 原來是header 少了RequestVerificationToken

如下取得RequestVerificationToken 的值 然後在AJAX的header加上RequestVerificationToken就可以了

var t = $("input[name='__RequestVerificationToken']").val();

function () {      

$.ajax

                    ({

                        url: "XXX",

                        headers:

                        {

                            "RequestVerificationToken": t

                        },

                        method: "POST",

                        data: { xxx: xxx,}

                    }

                    );

            });



然後這樣正常之後 然後 同一頁面 顯示另一個資料時竟然又出現400

用開發者工具的Network 看了一下 竟然header的token沒出現 不是一樣的程式嗎?

原來這個token是因為在Program.cs有寫了

builder.Services.AddControllersWithViews(options => {

   options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());

});

但是要有form 才會出現這個token 剛好我換一筆資料並沒有產生任何form 所以就沒有token了 找個地方加上

 <form method="post"> </form>
就正常了

2021年12月24日 星期五

如何從把原本在MAC的Parallels desktop 的windows 10的虛擬機升級到windows 11, Parallels Desktop windows 10 VM upgrade to windows 11 on a MAC

Windows 11已經出一段時間了 

但是parallels desktop的win10 vm一直沒有出現更新windows 11

結果是我的VM不符合windows 11升級之資格

要把Parallels Desktop 的Windows 10 VM升級到Windows 11有些步驟

Some steps to upgrade Parallels Desktop's Windows 10 VM to Windows 11

1.要把Parallels Desktop 升級到17.1以後版本 

1. To upgrade Parallels Desktop to version 17.1 or later

2.需把win10 VM升級到2004之後的版本

2. Need to upgrade win10 VM to the version after 2004

3.VM記憶體需要有4GB以上,儲存空間需有64GB以上,Win10 需有正版授權

3.VM memory needs to be 4GB or more, storage space needs to be 64GB or more, and Win10 needs a genuine license

4.把VM關機

4.Turn off the VM

5.在Win10 VM的控制中心組態的硬體 左下角的+號按下去增加 TPM晶片的硬體

5.Open VM configuration settings > Hardware 

Scroll down the hardware list and check if the TPM chip is added:

如下parallels的介紹

https://kb.parallels.com/en/128559

6.Win10 VM開機 按開始->設定->Windows Update 就會出現Windows 11的升級可以更新

6.Boot Win10 VM and press Start->Settings->Windows Update, and Windows 11 upgrade can be updated.

或是 執行電腦健康情況檢查應用程式後 下載 Windows 11安裝小幫手 就可以升級Windows 11

Or after running the Widnows PC Health Check APP, download Windows 11 Installation Assistant to upgrade Windows 11

2021年12月23日 星期四

某個罕見的中文字在asp.net 網站使用report viewer 產生的 pdf無法顯示會變成方匡

今天遇到一個中文字的狀況
就是在asp.net 網站產生的PDF 無法顯示那個中文字在mac電腦也無法顯示那個中文字

但是在windows下用winform 程式用word元件產生的pdf卻可以顯示那個字 

這個字如下網頁在Windows 下可以顯示字 但是mac無法顯示那個字https://ctext.org/dictionary.pl?if=gb&char=%F0%A5%A1%A5

後來找到原因是因為原本網頁的report viewer 是2010

只要更新成report viewer 2015 後就可以正常顯示 下面可以抓

Report Viewer 2015 Runtime

再裝Report Viewer 2015 RunTime前可能要先裝SQLSysClrTypes For SQL Server 2014

SQL Sys Clr Types For Sql Server 2014

更新需把web.config 更新一下

在<system.web><assembly>

<add assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>

<add assembly="Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/> 

在<system.webServer><handlers>下

<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />


更新之後再從web重新產生pdf那個奇怪的 種 字 就可以正常顯示在mac的pdf也可以看到他

2021年11月9日 星期二

安裝Visual Studio 2022 後Visual Studio 2019 專案無法載入 出現error: 無法開啟專案檔。找不到.NET SDK。請檢查是否安裝該項目,且在global.json中指定版本(如果有的話)是否安裝版本相符

昨天正式發表Visual Studio 2022 所以就來安裝 
結果我安裝Visual Studio 2022後 Visual Studio 2019 全部的專案都無法載入 出現
"error: 無法開啟專案檔。找不到.NET SDK。請檢查是否安裝該項目,且在global.json中指定版本(如果有的話)是否安裝版本相符。"
 如下圖
英文為
“The project file cannot be opened. Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.”
上網都查不到原因 google了很久
查到這個網站有解法
https://hamidmosalla.com/2021/03/13/unable-to-locate-the-net-sdk-the-reasons/

在環境變數裡面的Path 把C:\Program(x86)\donet\ 刪掉就可以正常開啟專案了
原因是安裝VS2022時多選擇安裝了.net 5 runtime

電腦按右鍵內容->進階->環境變數
環境變數->系統變數->Path->編輯

找到C:\Program Files(x86)\dotnet\ 按刪除


2021年9月8日 星期三

CS0656 遺漏編譯器必要成員'Microsoft.CSharp.RuntimeBinder.Binder.Convert'

 把.net framework 3.5的專案升級到.net framework 4.8時出現了一個錯誤如圖

CS0656 遺漏編譯器必要成員'Microsoft.CSharp.RuntimeBinder.Binder.Convert'

英文是 "Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.Convert'"



上網找到解決方法就是加入一個參考 在C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Microsoft.CSharp.dll

如下圖

然後就可以正常編譯過了

2021年6月6日 星期日

Dell R740 出現Unable to access Front LED Panel because of a hardware condition

 今天Dell R740 的Server 竟然出現

Unable to access Front LED Panel because of a hardware condition
還有紅底白字的 System HAS CRITICAL ISSUES
現場人去現場看LED 前面板顯示也很奇怪
結果call Dell維修竟然 說更新iDrac就可以了
所以就照著指示去更新到4.40.10.00完之後就正常了 錯誤訊息就不出現了

以下為Dell客服的回覆