Skip to content

All unit tests fail because of Mono.Unix.UnixPath in BuildPath #1040

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

Merged
merged 1 commit into from
May 23, 2015

Conversation

nulltoken
Copy link
Member

I just rebased my fork with latest from the vNext branch and hit an issue, which seems to be directly related to PR #1018 - all unit tests fail with the following exception:

System.TypeInitializationExceptionThe type initializer for 'LibGit2Sharp.Tests.TestHelpers.BaseFixture' threw an exception.
   at LibGit2Sharp.Tests.TestHelpers.BaseFixture..ctor()
   at LibGit2Sharp.Tests.CheckoutFixture..ctor()
System.TypeInitializationExceptionThe type initializer for 'LibGit2Sharp.Tests.TestHelpers.Constants' threw an exception.
   at LibGit2Sharp.Tests.TestHelpers.BaseFixture.IsFileSystemCaseSensitiveInternal() in BaseFixture.cs: line 94
   at LibGit2Sharp.Tests.TestHelpers.BaseFixture.SetUpTestEnvironment() in BaseFixture.cs: line 57
   at LibGit2Sharp.Tests.TestHelpers.BaseFixture..cctor() in BaseFixture.cs: line 29
System.Reflection.TargetInvocationExceptionException has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at LibGit2Sharp.Tests.TestHelpers.Constants.BuildPath() in Constants.cs: line 46
   at LibGit2Sharp.Tests.TestHelpers.Constants..cctor() in Constants.cs: line 9
System.BadImageFormatExceptionAn attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
   at Mono.Unix.Native.Syscall.readlink(String path, StringBuilder buf, UInt64 bufsiz)
   at Mono.Unix.UnixPath.ReadSymbolicLink(String path)
   at Mono.Unix.UnixPath.GetRealPath(String path)
   at Mono.Unix.UnixPath.GetCompleteRealPath(String path)

I'm running on Windows 8.1 and VS2013 and the var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); (found here) type is actually not null even though I'm not running *nix. I actually don't know what added Mono.Unix.UnixPath to my GAC, but its obviously causing problems.

It was mentioned in #1018 that Mono.Runtime was used elsewhere to check if "We're running on top of .Net", and changing the type actually makes the unit tests runnable again.

@carlosmn
Copy link
Member

carlosmn commented May 6, 2015

This isn't about checking whether we're on Mono, it's about figuring out the actual path to the temporary directory on OS X. We would have to do the same under CoreCLR. Having Mono.Posix on Windows is quite odd. It'd be unfortunate if we weren't able to reliably detect whether we can use it.

@sitereactor
Copy link
Contributor Author

I tried to track down where it comes from, and as far as I can tell its from GtkSharp (C:\Program Files (x86)\GtkSharp\2.12\lib\Mono.Posix\Mono.Posix.dll file version 2.0), and its installed with Xamarin, Inc. as the Publisher (installed as Gtk# for .Net 2.12.20).

After uninstalling this everything runs fine again. I'm assuming this is something that is left behind from having Xamarin installed for Visual Studio.

@Therzok
Copy link
Member

Therzok commented May 6, 2015

Ah, yes, Xamarin Studio puts some assemblies in the GAC. Sadly, I haven't had time to look at working around it and nuget-ing the assemblies.

@carlosmn
Copy link
Member

carlosmn commented May 6, 2015

That's very unfortunate. We will have to add a check for the OS as well before we try to use Mono.Posix in that case.

@nulltoken
Copy link
Member

@sitereactor Nice catch!

IIRC, BaseFixture.cs exposes a helper function IsRunningOnUnix().

Could you check if combining this test would solve the issue?

@damageboy
Copy link

In my other xplat projects, I also have to use Mono.Posix only when in Mono/Unix (depends on the use case).

The way I always do it is that I put the Mono.Posix dependent functionality in a separate function and the Windows functionality in yet a separate function, something like this:

void public DoSomething()
{
  if (RuntimeSupport.IsRunningOnUnix())
    DoSomethingMono();
  else
    DoSomethingOnWindows();
}

The only calls into Mono.Posix are coming in from DoSomethingMono() which never gets called EVEN A SINGLE TIME when running on Windows and vice-versa.

This, in turn means that the DoSomethingMono() function never gets JIT'd and you can deploy this on a windows machine, where Mono.Posix doesn't even have to exist(!) and everything will work just fine..

When on Linux/Mac, Mono.Posix is part of the "package", e.g. part of Mono, and there's never a chance of not finding it or calling into the wrong (too old one) that you packaged yourself...

nulltoken added a commit that referenced this pull request May 14, 2015
@nulltoken
Copy link
Member

@damageboy I've pushed something along your proposal.

/cc @jamill I've tried to load the type in a slightly different way in order to not be tied to a specific version of the assembly.

@nulltoken
Copy link
Member

Grmpf. Something went wrong

Travis Mac OS X build log states

Test working directory set to '/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/LibGit2Sharp-TestRepos'

This should rather be private/var/...

Could a good soul running on this platform could take a look at and find out where I messed up, please?

@bording
Copy link
Member

bording commented May 14, 2015

Pretty sure that path is where mono puts Shadow Copy stuff.

Try adding ShadowCopy="false" to CI/build.msbuild like I did in #984 and see what happens then.

@nulltoken
Copy link
Member

@bording Build in progress...

@nulltoken
Copy link
Member

@bording Didn't help. Still getting

/Users/travis/build/libgit2/libgit2sharp/LibGit2Sharp.Tests/bin/Release/LibGit2Sharp.Tests.dll Information : 0 : Test working directory set to '/var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/LibGit2Sharp-TestRepos'

@bording
Copy link
Member

bording commented May 14, 2015

😦 Sorry, thought that might be the solution. I'll try and take a look at this tonight then to see what's going on.

@bording
Copy link
Member

bording commented May 15, 2015

Aha, the problem is with the IsRunningOnUnix check, that is returning false, so the windows code path is being taken.

I noticed that the Using default test path value message was showing up in the build log when it shouldn't be, and I added an extra Trace call to print out a message in the unix path.

It's not showing up.

@bording
Copy link
Member

bording commented May 15, 2015

And, I think I know why. Both TemporaryReposPath and IsRunningOnUnix are being set with a field initializer, and BuildPath() is being called before the value of IsRunningOnUnix has been set, so it's always false.

About to push a change to confirm.

@bording
Copy link
Member

bording commented May 15, 2015

Ok, so that did fix the problem with it never calling UnwrapUnixTempPath() and only failing on OS X.

Now it's failing on both of them because it doesn't like how you're trying to load the Mono.Posix assembly:

System.TypeInitializationException : An exception was thrown by the type initializer for LibGit2Sharp.Tests.TestHelpers.BaseFixture

---- System.TypeInitializationException : An exception was thrown by the type initializer for LibGit2Sharp.Tests.TestHelpers.Constants

-------- System.IO.FileNotFoundException : Could not load file or assembly 'Mono.Posix' or one of its dependencies. The system cannot find the file specified.

@bording
Copy link
Member

bording commented May 15, 2015

Assembly.Load() requires the full name of the assembly, so just using Mono.Posix isn't going to work.

@bording
Copy link
Member

bording commented May 15, 2015

And there we go, green all around! 🎉

bording added a commit that referenced this pull request May 23, 2015
bording added a commit that referenced this pull request May 23, 2015
@nulltoken
Copy link
Member

@bording Thanks for the help!

Just removed some code duplication on top of it.

Good to go?

@bording
Copy link
Member

bording commented May 23, 2015

👍

nulltoken added a commit that referenced this pull request May 23, 2015
All unit tests fail because of Mono.Unix.UnixPath in BuildPath
@nulltoken nulltoken merged commit 645d89e into vNext May 23, 2015
@nulltoken nulltoken deleted the ntk/issue_1040 branch May 23, 2015 20:28
@nulltoken
Copy link
Member

@sitereactor Nice report, Sir! Thanks a lot for this ✨
@damageboy Your idea made it into a fix! 👍
@bording 😍

@nulltoken nulltoken added this to the v0.22 milestone May 23, 2015
@nulltoken
Copy link
Member

Published as NuGet pre-release package LibGit2Sharp.0.22.0-pre20150527180327

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

Successfully merging this pull request may close these issues.

6 participants