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

dll not found, native transitive dependency #4343

Open
coonsd opened this issue Mar 14, 2023 · 4 comments
Open

dll not found, native transitive dependency #4343

coonsd opened this issue Mar 14, 2023 · 4 comments
Labels
needs-triage This item should be discussed in the next triage meeting.

Comments

@coonsd
Copy link

coonsd commented Mar 14, 2023

Description

Our unit test project is targeting net47, using xunit and xunit.runner.visualstudio. The test has a transitive dependency that is native (Yubico.NativeShims), but the dll isn't being copied to the test directory resulting in a failed test with the message:

System.DllNotFoundException : Unable to load DLL 'Yubico.NativeShims.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

However, if you look at the build directory (bin\Debug\net47) you'll see that Yubico.NativeShims.dll is present. I’m opening this issue in vstest as it appears the vstest project is responsible for creating and staging the temporary test directory.

Our team owns Yubico.NativeShims, and we are using the buildtransitive NuGet directive to specify a targets file that copies over the native dependency for native users (see the Yubico.NativeShims project for more information).

Steps to reproduce

I created this project to demonstrate the issue. First build the solution (config: debug, any CPU). Next, run the one unit test in the project, ComputeSharedSecretTests.ComputeSecret_Matches().

Expected behavior

The test passes.

Actual behavior

The test fails, and in the test results you'll see the following message:

System.DllNotFoundException : Unable to load DLL 'Yubico.NativeShims.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Diagnostic logs

Microsoft (R) Test Execution Command Line Tool Version 17.4.1-release-20221129-02 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Logging Vstest Diagnostics in file: C:\...\demo-net47-transitive-dependency\UnitTests\bin\Debug\net47\log.txt
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit Desktop .NET 4.0.30319.42000)
[xUnit.net 00:00:04.55]   Discovering: UnitTests
[xUnit.net 00:00:04.76]   Discovered:  UnitTests
[xUnit.net 00:00:04.76]   Starting:    UnitTests
[xUnit.net 00:00:05.16]     UnitTests.ComputeSharedSecretTests.ComputeSecret_Matches [FAIL]
[xUnit.net 00:00:05.16]       System.DllNotFoundException : Unable to load DLL 'Yubico.NativeShims.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[xUnit.net 00:00:05.16]       Stack Trace:
[xUnit.net 00:00:05.16]            at Yubico.PlatformInterop.NativeMethods.BnBinaryToBigNum(Byte[] buffer, Int32 length, IntPtr ret)
[xUnit.net 00:00:05.16]            at Yubico.PlatformInterop.NativeMethods.BnBinaryToBigNum(Byte[] buffer)
[xUnit.net 00:00:05.16]            at Yubico.Core.Cryptography.EcdhPrimitivesOpenSsl.GenerateKeyPair(ECCurve curve)
[xUnit.net 00:00:05.16]         C:\...\demo-net47-transitive-dependency\UnitTests\ComputeSharedSecretTests.cs(31,0): at UnitTests.ComputeSharedSecretTests.ComputeSecret_Matches()
[xUnit.net 00:00:05.17]   Finished:    UnitTests
  Failed UnitTests.ComputeSharedSecretTests.ComputeSecret_Matches [234 ms]
  Error Message:
   System.DllNotFoundException : Unable to load DLL 'Yubico.NativeShims.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  Stack Trace:
     at Yubico.PlatformInterop.NativeMethods.BnBinaryToBigNum(Byte[] buffer, Int32 length, IntPtr ret)
   at Yubico.PlatformInterop.NativeMethods.BnBinaryToBigNum(Byte[] buffer)
   at Yubico.Core.Cryptography.EcdhPrimitivesOpenSsl.GenerateKeyPair(ECCurve curve)
   at UnitTests.ComputeSharedSecretTests.ComputeSecret_Matches() in C:\...\demo-net47-transitive-dependency\UnitTests\ComputeSharedSecretTests.cs:line 31

Test Run Failed.
Total tests: 1
     Failed: 1
 Total time: 5.3646 Seconds

Environment

Windows 11, OS Build: 22621.1265
Test Execution Command Line Tool Version 17.4.1-release-20221129-02 (x64)

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage This item should be discussed in the next triage meeting. label Mar 14, 2023
@NiuBClass666
Copy link

NiuBClass666 commented Mar 17, 2023

I got the similar issue on a net48 c# project. The dll could be found 1 day ago and nothing changed. Then suddenly, it can't find the dll in bin/debug folder but using dir or diagnostic option can confirm that the needed dll is in that folder. In the VsBuild task, it also logs that that dll was copied to the right folder.

NUnit Adapter 4.3.1.0 is used in my case. Microsoft (R) Test Execution Command Line Tool Version 17.5.0.

My solution: For my case, It turns out that it was caused by the latest update of Windows Server 2022 (20230314) image running on Azure agent which no longer has Microsoft Visual C++ 2010 Redistributable package pre-installed. So preinstalling that fixed my issue.

@ryansusername00
Copy link

ryansusername00 commented Mar 21, 2023

Same issue happened to my team last week. CI failed during testing with no related changes, and consistently failed from then on out.

@johanrex
Copy link

@coonsd I'm having the same issue. Is there a workaround?

@coonsd
Copy link
Author

coonsd commented Apr 3, 2023

@coonsd I'm having the same issue. Is there a workaround?

@johanrex Not that I know of, unfortunately. Hoping to get some feedback from the vstest team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage This item should be discussed in the next triage meeting.
Projects
None yet
Development

No branches or pull requests

4 participants