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

dotnet xunit fails to load dependent DLLs, but dotnet test succeeds #1509

Closed
Aaronontheweb opened this issue Oct 13, 2017 · 11 comments
Closed

Comments

@Aaronontheweb
Copy link

Currently in the process of debugging akkadotnet/akka.net#3150

When I work on the following .CSPROJ within the solution: https://github.com/akkadotnet/akka.net/tree/dev/src/contrib/persistence/Akka.Persistence.Sqlite.Tests

dotnet xunit is able to execute the unit tests just fine for the .NET 4.5.2 target, but when it comes time to execute the .NET Core 1.1 target the runner is unable to find the sqlite.dll dependency, which is referenced in a child project's NuGet dependencies.

        [ERROR][10/13/2017 4:49:26 PM][Thread 0175][akka://SqliteCurrentEventsByPersistenceIdSpec/system/akka.persistence.journal.sqlite] Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
        Cause: [akka://SqliteCurrentEventsByPersistenceIdSpec/system/akka.persistence.journal.sqlite#2004861133]: Akka.Actor.ActorInitializationException: Exception during creation ---> System.DllNotFoundException: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
           at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
           at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
           at Microsoft.Data.Sqlite.SqliteConnection.Open()

This issue occurred rather suddenly this week after we upgraded to 2.3.0. The part that confuses me is that if we run the same specifications on .NET Core using dotnet test instead of dotnet xunit, everything runs fine and the tests all pass.

Any idea what's occurring here?

@bradwilson
Copy link
Member

Please try with the latest 2.4 beta 1 build from our CI builds on MyGet, as this is likely already fixed (and planned for 2.3.1). Let me know if you're still having issues even with the latest build.

@Aaronontheweb
Copy link
Author

Thanks @bradwilson, I'll give that a try - might be related to #1490

@jp7677
Copy link

jp7677 commented Oct 15, 2017

@bradwilson I'm seeing the same FileNotFoundException here https://github.com/jp7677/hellocoreclr/tree/master/test/HelloCoreClrApp.Test
since I moved to 2.3.0 final. Everything is fine with dotnet test and was fine with the latest 2.3 beta. I have tested locally with 2.4.0-beta from nuget and that fixes the FileNotFoundException indeed. Thanks, looking forward to 2.3.1.

Please note though that even with 2.4.0-beta I'm still seeing test failures that are successful with dotnet test and the latest 2.3 beta. The exception looks like:

 System.MissingMethodException : Method not found: 'Void Newtonsoft.Json.JsonWriter.set_AutoCompleteOnClose(Boolean)'.
      Stack Trace:
           at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.CreateJsonWriter(TextWriter writer)
           at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.WriteObject(TextWriter writer, Object value)
           at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.<WriteResponseBodyAsync>d__9.MoveNext()

I wonder if this is related to that commit: e79a5ab

@bradwilson
Copy link
Member

@jp7677 Your problem is a dup of (the bottom half of) #1060.

@AleksanderKrolasik
Copy link

AleksanderKrolasik commented Nov 6, 2017

I have similar problem. Tests passes when I run them from visual studio but fails when run by xunit.console. I import dll using DllImport. Tests fails with message:

System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Cant solve the problem.

And second thing, when I use FreeLibrary, tests stops:

`[DllImport("kernel32", SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);

@bradwilson
Copy link
Member

An attempt was made to load a program with an incorrect format.

This usually means that the image you're trying to load is wrong for some reason: wrong bitness (i.e., 32-bit instead of 64-bit) or the wrong CPU (i.e., ARM instead of Intel).

@bradwilson
Copy link
Member

And second thing, when I use FreeLibrary, tests stops

Open a new issue with a repro project, please.

@adamrodger
Copy link

adamrodger commented Nov 8, 2017

It's the same if you try to read a file (e.g. NLog config) from the current directory. It looks like dotnet-xunit changes the current working directory from MyProject/bin/Debug/netcoreapp1.1 to the directory of xUnit itself. When I run my integration tests with dotnet xunit I get:

System.IO.FileNotFoundException : Could not find file 'C:\Users\<username>\.nuget\packages\dotnet-xunit\2.3.1\tools\netcoreapp1.0\nlog.config'

...because my code just tries to access nlog.config from the current directory as a relative path (e.g. File.ReadAllText("nlog.config"). When I run dotnet test then it works fine.

@adamrodger
Copy link

From looking at the source code, there's a few places where it does:

#if NET452
    Directory.SetCurrentDirectory(Path.GetDirectoryName(TestAssembly.Assembly.AssemblyPath));
#endif

e.g. https://github.com/xunit/xunit/blob/c7140cbc14a0d190931add88c2c0be9f3f2de440/src/xunit.execution/Sdk/Frameworks/Runners/TestAssemblyRunner.cs#L185-187

Using this, I changed my project to run as net452 instead of netcoreapp1.1 and now everything works correctly. It looks like the current directory is only broken when running on .Net Core instead of .Net Framework.

@bradwilson
Copy link
Member

Original issue is fixed. If there are still outstanding things, please open new issues.

@adamrodger
Copy link

Raised #1579

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

5 participants