最近在新的專案寫 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 檔案
根據之前處理問題的經驗,看到 debugger 會想到會不會與 Just My Code 有關係,經確認後發現有人在NUnit github 留言也遇到類似問題,接著到 Visual Studio 確認設定是否有開啟
- 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}
- The file 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs' does not exist.
- Looking in script documents for 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'...
- Looking in the Edit-and-Continue directory 'D:\SourceCode\Git\urapplication folder\'...
- The file with the matching checksum was not found in the Edit-and-Continue directory.
- Looking in the projects for 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'.
- The file was not found in a project.
- Looking in directory 'D:\'...
- Searching for documents embedded in the symbol file.
- An embedded document was not found.
- 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.
- The debugger could not locate the source file 'C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs'.
設定 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,
參考
0 意見:
張貼留言