Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectoryNotFoundException .NET 6 Workaround / Fix #362

Open
woodman231 opened this issue Apr 14, 2022 · 0 comments
Open

DirectoryNotFoundException .NET 6 Workaround / Fix #362

woodman231 opened this issue Apr 14, 2022 · 0 comments

Comments

@woodman231
Copy link

Hello,

I had a very difficult time for a while using the "Debug" link in my unit tests.

I created a project using a Development Container, targeting .NET 6.

I then created a class library and unit test project as described here

https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test

At first the tests weren't discovered but that was fixed by setting my "dotnet-test-explorer.testProjectPath" to "**/*.sln"

The tests at this point worked both by running dotnet test, and by using the Test Explorer UI.

However, when I tried to Debug I constantly got errors like this:

----- Debugging test method Prime.UnitTests.Services.PrimeService_IsPrimeShould.IsPrime_ValuesLessThan2_ReturnFalse -----

Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/workspace/unit-testing-using-dotnet-test/PrimeService/bin/Debug/net6.0/ref/PrimeService.dll'. [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]

Build FAILED.

/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/workspace/unit-testing-using-dotnet-test/PrimeService/bin/Debug/net6.0/ref/PrimeService.dll'. [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
/usr/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/workspace/unit-testing-using-dotnet-test/PrimeService/PrimeService.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:01.27

After reviewing OmniSharps documentation I learned that I need to set my "omnisharp.useModernNet" to true, and that resolved my issue, and I am now able to debug unit tests properly.

So in the end the resolution for me was to modify my .vscode/settings.json file to the following:

{
    "dotnet-test-explorer.testProjectPath": "**/*.sln",
    "omnisharp.useModernNet": true
}

I hope that helps somebody else too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant