只有累積,沒有奇蹟

2019年1月8日 星期二

[UnitTest] Reflect.cs not found in NUnit

問題
最近在新的專案寫 UnitTest 過程中,執行完後 Visual Studio 卻跳出 Source Not Fount : Reflect.cs not found 錯誤但單元測試還是可以成功如下圖
且透過 debug UnitTest 時發現測試的值也沒問題,經搜尋後發現是 Visual Studio 2017 IDE 設定問題,將這篇文章簡單紀錄處理問題過程

處理方式
釐清問題
按下 Source search information 可以發現更多錯誤內容及資訊發現是 Debugger 在 debug 的過程中找不到 nUnit Framework 的 Reflect.cs 檔案
  1. Locating source for 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'. Checksum: SHA1 {db ae 17 40 7a 46 56 f6 79 ee 5a 25 c7 7 94 f1 97 c1 a5 de}
  2. The file 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs' does not exist.
  3. Looking in script documents for 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'...
  4. Looking in the Edit-and-Continue directory 'D:\SourceCode\Git\urapplication folder\'...
  5. The file with the matching checksum was not found in the Edit-and-Continue directory.
  6. Looking in the projects for 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'.
  7. The file was not found in a project.
  8. Looking in directory 'D:\'...
  9. Searching for documents embedded in the symbol file.
  10. An embedded document was not found.
  11. The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs.
  12. The debugger could not locate the source file 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'.
根據之前處理問題的經驗看到 debugger 會想到會不會與 Just My Code 有關係,經確認後發現有人在NUnit github 留言也遇到類似問題,接著Visual Studio 確認設定是否有開啟

設定 Just My Code 
Step 1 : 搜尋設定可以到 IDE 右上角Quick Lauch 搜尋需要找的設定,會列出該設定位置
Step 2 : Just My Code 打勾
Step 3 : 在重新測試一次,此問題就不會在發生了

補充 : Just My Code 是甚麼
當在 Application 進行 Debug 的時候debugger 會嘗試去找正在執行的 symbols 中的代碼,它才可以知道開發者在哪段 Code 有設定中斷點,蒐集加入監看示的變數內容或是檢查 Call Stack 等資訊,在 Visual Studio 中 debug 時預設會跳過不屬於此專案的代碼或是 assemblies這設定名稱為 Just My Code

參考


Related Posts:

  • [UnitTest] 如何測試目標方法中 Guid 型別的代碼 ?情境 如果要產生一個亂數時很常會想到 Guid 方法解決,在 C# 使用 Guid 的方式相當簡單僅要透過  Guid.NewGuid  靜態方法產生一組 Guid 使用,在目前公司很常看到使用 Guid 作為識別碼,今天在重構舊代碼時忽然想到如果遇到 Guid 該如何進行加上單元測試,以下就目前想到的解法進行測試與說明,如果各位高手們有更好的方法歡迎高抬貴手一起討論研究。 解決方案 寫個簡單的 Sa… Read More
  • [.NETCore] ASP.NET Core 學習資源包 - awesome dotnetcore前言 最近比較多機會嘗試有興趣的新技術,在學習過程中勢必會遇到很多疑難雜症;像是最近新專案使用 ASP.NET Core 開發,有些觀念如果你 ASP.NET Framework 習慣了轉到新的會需要點時間,這時如果有份清單整理技術領域相關內容是在好不過的了;今天要分享的是 github 上的 awesome dotnet core,集合群眾的力量整理 ASP.NET Core 的學習資源與相關 Library 資訊,另外如果有好康的想要分享給大… Read More
  • [UnitTest] ASP.NET Core 2.2 測試專案中的版本衝突 問題  這幾天專案某項功能接近尾聲,要替其核心 ASP.NET Core 專案加上單元測試專案,加入後按下建置發現跳出 Error 錯誤訊息  "CS1705 Assembly 'xxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.Extensions.Logging.Abstractions, Version=2.… Read More
  • [.NETCore] 如何取得 appsettings.json 組態設定問題 在開發時有時會將資訊紀錄在 Web.Config 設定檔中的開發經驗,在 .NET Framework 要取得 web.config 自訂組態設定時可以透過  ConfigurationManager.AppSettings ,相信大家都有了解且不陌生;但今天場景換到 ASP.NET Core 時,在一開始建立好新專案後只有  appsettings.json  設定檔,那麼該如何… Read More
  • [IIS] 程序無法存取檔案,因為檔案正由另一個程序使用。(發生例外狀況於HRESULT:0x80070020)問題 今天要在公司測試 Server 建立測試站台,在完成設定 Application Pool 與站台指定位置後按下啟動,跳出'程序無法存取檔案,因為檔案正由另一個程序使用。(發生例外狀況於HRESULT:0x80070020) 錯誤訊息,訊息內容看似有檔案被 lock 住造成啟動異常,但追根究底之後會發現其異常原因蠻單純的,以下就針對解決此問題的方式做說明,若有問題歡迎提出一起討論或是給予指導。 解決方案 根… Read More

0 意見:

張貼留言

Copyright © 2025 m@rcus 學習筆記 | Powered by Blogger

Design by Anders Noren | Blogger Theme by NewBloggerThemes.com