4

解決 VS2022 無法偵錯 32 位元 Web Site Project 問題

 1 year ago
source link: https://blog.darkthread.net/blog/debug-32bit-wsp-on-vs2022/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

解決 VS2022 無法偵錯 32 位元 Web Site Project 問題-黑暗執行緒

Visual Studio 從 2022 起轉為 64 位元,4GB 封印解除,自此編輯測試時可以充分利用開發機記憶體,面對複雜專案也不用怕。

不過,從 32 位元改為 64 位元有帶來一些後遺症,過去已經歷過:

第二點比較麻煩,典型案例是引用 ODP.NET 的 Web Site Project (WSP) 專案,這類古蹟專案多半還未升級到 Managed ODP.NET,不時會陷入 32 位元 vs 64 位元或 Oracle Client 不匹配的版本地獄,在 VS2022 上爆發只是剛好而已。(衷心建議,若能換 Managed ODP.NET 就塊陶吧~)

因此,若你是用 VS2022 維護呼叫 32 位元 ODP.NET 程式庫的 WSP 專案,便會陷入無法偵錯的困境。

例如,用一個超簡單的 WSP 當範例,專案參照 32 位元 ODP.NET (Oracle.DtaAccess.dll.refresh 內容為 ..\..\Oracle\product\12.2.0\client32\odp.net\bin\4\Oracle.DataAccess.dll),寫個 WebForm 測試:

<%@Page Language="C#"%>
<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        var asm = typeof(Oracle.DataAccess.Client.OracleConnection).Assembly;
        Response.ContentType = "text/plain";
        Action<string> write = (m) => Response.Write(m + "\n");
        write(Environment.Is64BitProcess ? "64bit" : "32bit");
        write(asm.FullName);

    }
</script>

試著偵錯或建置網站會出現不認得 Oracle.DataAccess.Client 錯誤:(原因是 VS2022 為 64 位元環境無法載入 32 位元版本 Oracle.DataAccess.dll)

Fig1_638236431812620379.png

但發佈網站或是 MSBuild 跑 publishproj 則會成功。

Fig2_638236431814426080.png

改參照 64 位元 ODP.NET,則 WSP 專案可以建置專案及偵錯,變成發佈時出現 32/64 版本不符錯誤:

Fig3_638236431816275204.png

Deadlock!

原以為無解,但意外找到一個簡單解法 - 偵錯時不要 Build 就好了! 在專案設定頁面將 Start action 的 Before running startup page 設成 No Build:

Fig4_638236431818102100.png

另外,記得停用 IIS Expression 64 位元模式:

Fig5_638236431819974482.png

調整後,就可以正常 F5 偵錯了,也能成功發佈 32 位元版本網站檔案,唯一的小問題 Visual Studio 跑 Build Web Site 還是會報錯。實測 .sln 參照的其他專案若有修改,Build Web Site 時會先被編譯才出錯,故古蹟維修可以順利進行,問題算是解決囉~

Fig6_638236431821772142.png

最後再勸世一下:珍惜生命,遠離 ODP.NET,若狀況允許快換成 Managed ODP.NET 吧!

and has 0 comments

Comments

Be the first to post a comment

Post a comment

Comment
Name Captcha 80 - 65 =

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK