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

System.BadImageFormatException: Method has no body on CentOS #1637

Open
kostyaVyrodov opened this issue Nov 6, 2018 · 15 comments
Open

System.BadImageFormatException: Method has no body on CentOS #1637

kostyaVyrodov opened this issue Nov 6, 2018 · 15 comments

Comments

@kostyaVyrodov
Copy link

kostyaVyrodov commented Nov 6, 2018

Reproduction steps

I use CAKE to automate build process. I run my build script on CentOS and it throws an exception

To reproduce the issue, try to create an instance of the 'Repository' class.
I've created a test project reproducing similar error, but on MacOS.

I also use CAKE script, but the original one is more complex than the test one, but in any way the library also throws similar exception related to native methods.

...
var repo = new Repository("./.git");
...

Actual behavior

Error: System.AggregateException: One or more errors occurred. ---> System.BadImageFormatException: Method has no body
  at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x002ee] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at LibGit2Sharp.Repository..ctor (System.String path) [0x00000] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at Submission#0.<<Initialize>>b__0_3 () [0x0000d] in <c937322efd9e45229071df73bf4f662f>:0 
  at Cake.Core.CakeTaskBuilderExtensions+<>c__DisplayClass17_0.<Does>b__0 (Cake.Core.ICakeContext context) [0x00000] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeTaskBuilderExtensions+<>c__DisplayClass20_0.<Does>b__0 (Cake.Core.ICakeContext x) [0x00000] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeTask.Execute (Cake.Core.ICakeContext context) [0x00066] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.DefaultExecutionStrategy.ExecuteAsync (Cake.Core.CakeTask task, Cake.Core.ICakeContext context) [0x000ee] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.ExecuteTaskAsync (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, System.Diagnostics.Stopwatch stopWatch, Cake.Core.CakeTask task, Cake.Core.CakeReport report) [0x00131] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.RunTask (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, Cake.Core.CakeTask task, System.String target, System.Diagnostics.Stopwatch stopWatch, Cake.Core.CakeReport report) [0x00124] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.RunTargetAsync (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, Cake.Core.ExecutionSettings settings) [0x00338] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Scripting.BuildScriptHost.RunTargetAsync (System.String target) [0x0009f] in <52bc22bce5254240ba373b3cf23da1ab>:0 
  at Cake.Core.Scripting.ScriptHost.RunTarget (System.String target) [0x0000d] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Submission#0+<<Initialize>>d__0.MoveNext () [0x00150] in <c937322efd9e45229071df73bf4f662f>:0 
  at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult] (System.Collections.Immutable.ImmutableArray`1[T] precedingExecutors, System.Func`2[T,TResult] currentExecutor, System.Runtime.CompilerServices.StrongBox`1[T] exceptionHolderOpt, System.Func`2[T,TResult] catchExceptionOpt, System.Threading.CancellationToken cancellationToken) [0x00186] in <3ee4bd870c1146d59b98317e4bbdcbe8>:0 
  at Microsoft.CodeAnalysis.Scripting.Script`1[T].RunSubmissionsAsync (Microsoft.CodeAnalysis.Scripting.ScriptExecutionState executionState, System.Collections.Immutable.ImmutableArray`1[T] precedingExecutors, System.Func`2[T,TResult] currentExecutor, System.Func`2[T,TResult] catchExceptionOpt, System.Threading.CancellationToken cancellationToken) [0x000a8] in <3ee4bd870c1146d59b98317e4bbdcbe8>:0 
   --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <3d1438d9da1e4fe0b915f807d1ba56bd>:0 
  at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00043] in <3d1438d9da1e4fe0b915f807d1ba56bd>:0 
  at System.Threading.Tasks.Task.Wait () [0x00000] in <3d1438d9da1e4fe0b915f807d1ba56bd>:0 
  at Cake.Scripting.Roslyn.RoslynScriptSession.Execute (Cake.Core.Scripting.Script script) [0x001a7] in <52bc22bce5254240ba373b3cf23da1ab>:0 
  at Cake.Core.Scripting.ScriptRunner.Run (Cake.Core.Scripting.IScriptHost host, Cake.Core.IO.FilePath scriptPath, System.Collections.Generic.IDictionary`2[TKey,TValue] arguments) [0x00358] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Commands.BuildCommand.Execute (Cake.CakeOptions options) [0x0003f] in <52bc22bce5254240ba373b3cf23da1ab>:0 
  at Cake.CakeApplication.Run (Cake.CakeOptions options) [0x00015] in <52bc22bce5254240ba373b3cf23da1ab>:0 
  at Cake.Program.Main () [0x000d1] in <52bc22bce5254240ba373b3cf23da1ab>:0 
---> (Inner Exception #0) System.BadImageFormatException: Method has no body
File name: 'LibGit2Sharp'
  at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00008] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options, LibGit2Sharp.Repository+RepositoryRequiredParameter requiredParameter) [0x002ee] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at LibGit2Sharp.Repository..ctor (System.String path) [0x00000] in <b59d5da32f8541b2a767004d8bddc22b>:0 
  at Submission#0.<<Initialize>>b__0_3 () [0x0000d] in <c937322efd9e45229071df73bf4f662f>:0 
  at Cake.Core.CakeTaskBuilderExtensions+<>c__DisplayClass17_0.<Does>b__0 (Cake.Core.ICakeContext context) [0x00000] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeTaskBuilderExtensions+<>c__DisplayClass20_0.<Does>b__0 (Cake.Core.ICakeContext x) [0x00000] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeTask.Execute (Cake.Core.ICakeContext context) [0x00066] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.DefaultExecutionStrategy.ExecuteAsync (Cake.Core.CakeTask task, Cake.Core.ICakeContext context) [0x000ee] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.ExecuteTaskAsync (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, System.Diagnostics.Stopwatch stopWatch, Cake.Core.CakeTask task, Cake.Core.CakeReport report) [0x00131] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.RunTask (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, Cake.Core.CakeTask task, System.String target, System.Diagnostics.Stopwatch stopWatch, Cake.Core.CakeReport report) [0x00124] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Core.CakeEngine.RunTargetAsync (Cake.Core.ICakeContext context, Cake.Core.IExecutionStrategy strategy, Cake.Core.ExecutionSettings settings) [0x00338] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Cake.Scripting.BuildScriptHost.RunTargetAsync (System.String target) [0x0009f] in <52bc22bce5254240ba373b3cf23da1ab>:0 
  at Cake.Core.Scripting.ScriptHost.RunTarget (System.String target) [0x0000d] in <1a12afcf649f4de8ab5d15d82d4f6310>:0 
  at Submission#0+<<Initialize>>d__0.MoveNext () [0x00150] in <c937322efd9e45229071df73bf4f662f>:0 
  at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult] (System.Collections.Immutable.ImmutableArray`1[T] precedingExecutors, System.Func`2[T,TResult] currentExecutor, System.Runtime.CompilerServices.StrongBox`1[T] exceptionHolderOpt, System.Func`2[T,TResult] catchExceptionOpt, System.Threading.CancellationToken cancellationToken) [0x00186] in <3ee4bd870c1146d59b98317e4bbdcbe8>:0 
  at Microsoft.CodeAnalysis.Scripting.Script`1[T].RunSubmissionsAsync (Microsoft.CodeAnalysis.Scripting.ScriptExecutionState executionState, System.Collections.Immutable.ImmutableArray`1[T] precedingExecutors, System.Func`2[T,TResult] currentExecutor, System.Func`2[T,TResult] catchExceptionOpt, System.Threading.CancellationToken cancellationToken) [0x000a8] in <3ee4bd870c1146d59b98317e4bbdcbe8>:0 <---

Expected behavior

The constructor returns an instance of the Repository

Version of LibGit2Sharp (release number or SHA1)

v0.25.3

Operating system(s) tested; .NET runtime tested

  • CentOS Linux release 7.5.1804 (Core)
  • Mono
Mono JIT compiler version 5.16.0.187 (tarball Mon Oct  8 08:52:21 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(3.6.0svn-mono-/)
	GC:            sgen (concurrent by default)
@ethomson
Copy link
Member

ethomson commented Nov 6, 2018

I don't know what you mean when you say that you use cake to automate the build process... It looks like cake is actually calling directly to LibGit2Sharp? I assume that it's capable of running scripts or something? And that you're creating a script that opens a repository?

@kostyaVyrodov
Copy link
Author

kostyaVyrodov commented Nov 6, 2018

@ethomson ,

It looks like cake is actually calling directly to LibGit2Sharp?

Yes, it does.

I've created a repository with a sample
Clone it and run $ sh ./build.sh --verbosity="diagnostic" to reproduce the problem, please.

Take attention that you've to have an installed mono.

P.S. Thank you for the great library and fast support :)

@ethomson
Copy link
Member

ethomson commented Nov 6, 2018

That repo you just created has an error message from macOS, but up top you mention that macOS works - can you clarify?

@kostyaVyrodov
Copy link
Author

kostyaVyrodov commented Nov 6, 2018

@ethomson,

That repo you just created has an error message from macOS, but up top you mention that macOS works - can you clarify?

Extremely good point, sorry for confusing.

The created test project also have a problem on MacOS, but it's a little bit different from the problem I have on CentOS. Could you run that script to check it?

I think I should change the description of the issue.

Interesting thing: if you add the line #addin Cake.Git to the build.cake the script on mac will work good.

Note: the script in the test project is different to another one I run on CentOS. But unfortunately the test script also has a problem.

@bording
Copy link
Member

bording commented Nov 6, 2018

@kostyaVyrodov I've seen other reports of the same error (Method has no body) when running on mono, so I think there's something wrong somewhere that is making LibGit2Sharp and mono very unhappy with each other. I've not had time to investigate the specifics yet, though.

On a side note, even if you weren't getting that error, you likely wouldn't be able to run on CentOS by default. You'll need to edit LibGit2Sharp.dll.config to point to the rhel-x64 binary instead of the linux-x64 binary.

@austinlparker
Copy link

I'm also seeing this error on Debian 9 when using Cake -

System.BadImageFormatException: Method has no body
File name: 'LibGit2Sharp'
  at LibGit2Sharp.Core.Proxy.git_buf_free (LibGit2Sharp.Core.Handles.GitBuf buf) [0x00000] in <8cb98e2882834fdfae1774f5509e9705>:0
  at LibGit2Sharp.Core.Handles.GitBuf.Dispose () [0x00000] in <8cb98e2882834fdfae1774f5509e9705>:0
  at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2[T,TResult] pathRetriever) [0x0002e] in <8cb98e2882834fdfae1774f5509e9705>:0
  at LibGit2Sharp.Core.Proxy.git_repository_discover (LibGit2Sharp.Core.FilePath start_path) [0x00005] in <8cb98e2882834fdfae1774f5509e9705>:0
  at LibGit2Sharp.Repository.Discover (System.String startingPath) [0x00006] in <8cb98e2882834fdfae1774f5509e9705>:0
  at GitVersion.GitPreparer.GetDotGitDirectory () [0x0000f] in <d0cdb28786d042cc8faa2061fd9fed03>:0
  at GitVersion.GitPreparer.GetProjectRootDirectory () [0x00048] in <d0cdb28786d042cc8faa2061fd9fed03>:0
  at GitVersion.ConfigurationProvider.Verify (GitVersion.GitPreparer gitPreparer, GitVersion.Helpers.IFileSystem fileSystem) [0x00014] in <d0cdb28786d042cc8faa2061fd9fed03>:0
  at GitVersion.Program.VerifyConfiguration (GitVersion.Arguments arguments, GitVersion.Helpers.IFileSystem fileSystem) [0x00023] in <d0cdb28786d042cc8faa2061fd9fed03>:0
  at GitVersion.Program.VerifyArgumentsAndRun () [0x00118] in <d0cdb28786d042cc8faa2061fd9fed03>:0

@bording
Copy link
Member

bording commented Nov 13, 2018

@austinlparker Is that from mono or .NET Core?

@austinlparker
Copy link

austinlparker commented Nov 13, 2018 via email

@t081as
Copy link

t081as commented Dec 1, 2018

The exception mentioned in this issue also appears when using the official Mono docker image:
https://gitlab.com/tobiaskoch/LinkTime/-/jobs/128307486

  • docker image: mono:latest
  • cake 0.30.0
  • Cake.Git.0.19.0 using LibGit2Sharp.dll 0.25.2.88

@cipri-p
Copy link

cipri-p commented Dec 11, 2018

Having the same error on a AWS Linux image with latest mono (Mono JIT compiler version 5.16.0.220 )

@t081as
Copy link

t081as commented Dec 11, 2018

I switched to the old Cake.Git version 0.18.0 (using libgit2sharp 0.24.10) which works as expected.

@bording
Copy link
Member

bording commented Dec 11, 2018

There is definitely some sort of compatibility problem between recent versions of LibGit2Sharp and mono, but I haven't had time to investigate the cause.

@cipri-p
Copy link

cipri-p commented Dec 11, 2018

thanks @bording

@t081as : I tried using the old Cake.git (0.18.0), but it didn't work for me.

However, what I'm trying to do is use GitVersion with Cake Build on a Linux machine running mono. From my investigation (also confirmed here "GitTools/GitVersion#1097") the issue seems to be introduce by a recent version of libgit2. If I manually change GitVersion to us libgit2 v0.27.0 I don't have this issue.

@pastmaster007
Copy link

@kostyaVyrodov were you able to resolve this issue?

recently, i ran into same issue with Xamarin project while using libgit2sharp nuget v0.26.0.

System.BadImageFormatException: Method has no body
File name: 'LibGit2Sharp'

I do not use cake but, expecting same fix would help here..

I fixed this issue in my project by referencing "LibGit2Sharp.NativeBinaries" package to executable file and it worked.

Can you make sure "libgit2-*.so" file is properly linked to your executable?

@StevePunak
Copy link

@pastmaster007. I am having the same issue. Could you please explain your fix further?

I fixed this issue in my project by referencing "LibGit2Sharp.NativeBinaries" package to executable file and it worked.

My LibGit2Sharp.NativeBinaries is implicitly included as a dependency of LibGit2Sharp by NuGet. There is no way I can see to add an explicit reference.

Can you make sure "libgit2-*.so" file is properly linked to your executable?
I am using C#. Are you describing a C++ solution?

Thanks

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

8 participants