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

cake fails to build on travis-ci with latest mono (6.8) #2695

Closed
mcleodia opened this issue Jan 16, 2020 · 14 comments · Fixed by #2707
Closed

cake fails to build on travis-ci with latest mono (6.8) #2695

mcleodia opened this issue Jan 16, 2020 · 14 comments · Fixed by #2707
Assignees
Labels
Milestone

Comments

@mcleodia
Copy link

What You Are Seeing?

Cake fails to compile and run build script. The error message is.
Error: The assembly name is invalid.

The problem appears to be related to Mono 6.8 - a temporary workaround that has fixed the issue for me was to add the line mono: 6.6.0 into the below travis.yml.

What is Expected?

Cake compiles and runs build script.

What version of Cake are you using?

The below log was generated using Cake 0.32.1, but as part of diagnosing the issue, I updated to 0.36.0 and it didn't make a difference.
I also created a hello world Cake script

Are you running on a 32 or 64 bit system?

What environment are you running on? Windows? Linux? Mac?

travis, linux, csharp environment as below.

Are you running on a CI Server? If so, which one?

travis

yml:

language: csharp
dotnet: 2.1.504
sudo: required
services:
  - docker
before_install:
  - export PATH=~/bin:$PATH
script:
  - chmod +x build.sh
  - ./build.sh

Cake script

var target = Argument("target", "Default");

Task("Default")
  .Does(() =>
{
  Information("Hello World!");
});

RunTarget(target);

How Did You Get This To Happen? (Steps to Reproduce)

A hello world cake script in conjunction with the above travis.yml should be enough to repro this issue.

Output Log

```
9.77s$ ./build.sh -t Build
Downloading NuGet...
  https://api.nuget.org/v3/index.json
Restoring NuGet package Cake.0.32.1.
  GET https://api.nuget.org/v3-flatcontainer/cake/0.32.1/cake.0.32.1.nupkg
  OK https://api.nuget.org/v3-flatcontainer/cake/0.32.1/cake.0.32.1.nupkg 18ms
Installing Cake 0.32.1.
Adding package 'Cake.0.32.1' to folder '/home/travis/build/linn/mylinn/tools'
Added package 'Cake.0.32.1' to folder '/home/travis/build/linn/mylinn/tools'
Analyzing build script...
Processing build script...
Installing addins...
Compiling build script...
Error: The assembly name is invalid.
The command "./build.sh -t Build" failed and exited with 1 during .
```
@HebaruSan
Copy link

It's not exclusive to Travis, I have the same problem on my Ubuntu machine after upgrading to Mono 6.8.

@HebaruSan
Copy link

--verbosity=Diagnostic prints a stack trace:

Compiling build script...
Error: System.IO.FileLoadException: The assembly name is invalid.
  at System.Reflection.AssemblyName..ctor (System.String assemblyName) [0x00043] in <c453bf849bb84e719dbec0475e99db95>:0 
  at Microsoft.CodeAnalysis.MonoGlobalAssemblyCache+<GetAssemblyIdentitiesAndPaths>d__6.MoveNext () [0x000af] in <7bf9c45d64ff4b6eb4df0e471c802d41>:0 
  at Microsoft.CodeAnalysis.MonoGlobalAssemblyCache.ResolvePartialName (System.String displayName, System.String& location, System.Collections.Immutable.ImmutableArray`1[T] architectureFilter, System.Globalization.CultureInfo preferredCulture) [0x00092] in <7bf9c45d64ff4b6eb4df0e471c802d41>:0 
  at Microsoft.CodeAnalysis.Scripting.Hosting.GacFileResolver.Resolve (System.String assemblyName) [0x00014] in <7bf9c45d64ff4b6eb4df0e471c802d41>:0 
  at Microsoft.CodeAnalysis.Scripting.Hosting.RuntimeMetadataReferenceResolver.ResolveMissingAssembly (Microsoft.CodeAnalysis.MetadataReference definition, Microsoft.CodeAnalysis.AssemblyIdentity referenceIdentity) [0x0001d] in <7bf9c45d64ff4b6eb4df0e471c802d41>:0 
  at Microsoft.CodeAnalysis.Scripting.ScriptMetadataResolver.ResolveMissingAssembly (Microsoft.CodeAnalysis.MetadataReference definition, Microsoft.CodeAnalysis.AssemblyIdentity referenceIdentity) [0x00000] in <7bf9c45d64ff4b6eb4df0e471c802d41>:0 
  at Microsoft.CodeAnalysis.CommonReferenceManager`2[TCompilation,TAssemblySymbol].ResolveAndBindMissingAssemblies (TCompilation compilation, System.Collections.Immutable.ImmutableArray`1[T] explicitAssemblies, System.Collections.Immutable.ImmutableArray`1[T] explicitModules, System.Collections.Immutable.ImmutableArray`1[T] explicitReferences, System.Collections.Immutable.ImmutableArray`1[T] explicitReferenceMap, Microsoft.CodeAnalysis.MetadataReferenceResolver resolver, Microsoft.CodeAnalysis.MetadataImportOptions importOptions, System.Boolean supersedeLowerVersions, Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder`1[T] referenceBindings, System.Collections.Generic.Dictionary`2[TKey,TValue] assemblyReferencesBySimpleName, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.CommonReferenceManager`2+AssemblyData[TCompilation,TAssemblySymbol]]& allAssemblies, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.MetadataReference]& metadataReferences, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.CommonReferenceManager`2+ResolvedReference[TCompilation,TAssemblySymbol]]& resolvedReferences, Microsoft.CodeAnalysis.DiagnosticBag resolutionDiagnostics) [0x00123] in <d2a099d1c1454fc88ba76c52254e7d7d>:0 
  at Microsoft.CodeAnalysis.CommonReferenceManager`2[TCompilation,TAssemblySymbol].Bind (TCompilation compilation, System.Collections.Immutable.ImmutableArray`1[T] explicitAssemblies, System.Collections.Immutable.ImmutableArray`1[T] explicitModules, System.Collections.Immutable.ImmutableArray`1[T] explicitReferences, System.Collections.Immutable.ImmutableArray`1[T] explicitReferenceMap, Microsoft.CodeAnalysis.MetadataReferenceResolver resolverOpt, Microsoft.CodeAnalysis.MetadataImportOptions importOptions, System.Boolean supersedeLowerVersions, System.Collections.Generic.Dictionary`2[TKey,TValue] assemblyReferencesBySimpleName, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.CommonReferenceManager`2+AssemblyData[TCompilation,TAssemblySymbol]]& allAssemblies, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.MetadataReference]& implicitlyResolvedReferences, System.Collections.Immutable.ImmutableArray`1[Microsoft.CodeAnalysis.CommonReferenceManager`2+ResolvedReference[TCompilation,TAssemblySymbol]]& implicitlyResolvedReferenceMap, Microsoft.CodeAnalysis.DiagnosticBag resolutionDiagnostics, System.Boolean& hasCircularReference, System.Int32& corLibraryIndex) [0x0003f] in <d2a099d1c1454fc88ba76c52254e7d7d>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation+ReferenceManager.CreateAndSetSourceAssemblyFullBind (Microsoft.CodeAnalysis.CSharp.CSharpCompilation compilation) [0x0007f] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation+ReferenceManager.CreateSourceAssemblyForCompilation (Microsoft.CodeAnalysis.CSharp.CSharpCompilation compilation) [0x00008] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetBoundReferenceManager () [0x00008] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics (Microsoft.CodeAnalysis.CompilationStage stage, System.Boolean includeEarlierStages, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, System.Threading.CancellationToken cancellationToken) [0x002ae] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics (Microsoft.CodeAnalysis.CompilationStage stage, System.Boolean includeEarlierStages, System.Threading.CancellationToken cancellationToken) [0x00006] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnostics (System.Threading.CancellationToken cancellationToken) [0x00000] in <6ad4116dfb37422ca62221cd1c4a63d8>:0 
  at Cake.Scripting.Roslyn.RoslynScriptSession.Execute (Cake.Core.Scripting.Script script) [0x0010e] in <5a0dca01265949b390a25c4808d7c9e6>: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 <0bee4796f971414eaddf3b40a0b757ef>:0 
  at Cake.Commands.BuildCommand.Execute (Cake.CakeOptions options) [0x0003f] in <5a0dca01265949b390a25c4808d7c9e6>:0 
  at Cake.CakeApplication.Run (Cake.CakeOptions options) [0x00015] in <5a0dca01265949b390a25c4808d7c9e6>:0 
  at Cake.Program.Main () [0x000d1] in <5a0dca01265949b390a25c4808d7c9e6>:0 

@HebaruSan
Copy link

HebaruSan commented Jan 16, 2020

I think the exception is thrown here:

https://github.com/mono/mono/blob/bafdd7865f1d407cd2fe9ce98bbcd40f7086eda6/mcs/class/corlib/System.Reflection/AssemblyName.cs#L104

So ParseAssemblyName is returning false. Unfortunately that function is extern, and I'm not able to find its implementation yet.

@HebaruSan
Copy link

HebaruSan commented Jan 16, 2020

I think mono/mono#16446 broke this five months ago. It added a check that rejects / characters in assembly names:

https://github.com/mono/mono/blob/bafdd7865f1d407cd2fe9ce98bbcd40f7086eda6/mono/metadata/assembly.c#L3526-L3532

And adding some more info to that exception reveals that Cake passes the full absolute path:

Error: The assembly name is invalid: /path/to/mono-dev/lib/mono/gac/System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll

Correction, Cake doesn't pass any paths explicitly, this may be entirely internal to Mono.
Or does it? I'm not sure now.

.AddReferences(ReferencePaths.Select(r => r.FullPath))

... ReferencePaths is empty, at least in my use case.

@laura-rodriguez
Copy link

I have the same issue on Travis. Is there any workaround for this?

@HebaruSan
Copy link

Try changing mono: latest to mono: 6.6.0 in your .travis.yml until this is fixed.

@laura-rodriguez
Copy link

Just saw that in the description 🤦‍♀ . Thanks @HebaruSan , I'm gonna try that.

@Julien-Molina
Copy link

Hi there, I have the same problem using cake with mono 6.8.0 on circle-ci

@devlead
Copy link
Member

devlead commented Jan 20, 2020

This seems to be a bug in the Mono runtime, see issue mono/mono#18508

If you have .NET Core installed on the machine you could try executing you script using Cake.Tool.

Quick way to bootstrap it would be to use local tools and bootsrap on ci somehing like dotnet tool restore && dotnet cake

Good examples in these blog posts:

laura-rodriguez added a commit to okta/okta-sdk-dotnet that referenced this issue Jan 21, 2020
@CoffeeFlux
Copy link

The Mono commit that changed this fixed our parsing to be in line with .NET Core, which in turn triggered a Roslyn bug that was relying on our old, broken behavior in some Mono-specific code (see dotnet/roslyn#39369 (comment)).

The Roslyn fix is in the 3.5.0-beta1 nuget, so if reasonable cake should try updating to that and things should work smoothly with Mono 6.8.

@metalfork
Copy link

Is there a timeline for updating cake to use a newer Microsoft.CodeAnalysis.CSharp.Scripting dependency with the roslyn preview that fixes this issue?
mono/mono#18508 (comment)
https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting/3.5.0-beta2-final

@devlead
Copy link
Member

devlead commented Jan 28, 2020

In general we try not to use preview versions as unstable versions might break other scenarios.
But raise an PR and we can see if any integration tests fail or cause issues.

@devlead
Copy link
Member

devlead commented Feb 1, 2020

@cake-build-bot
Copy link

cake-build-bot commented Feb 1, 2020

🎉 This issue has been resolved in version v0.37.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

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

Successfully merging a pull request may close this issue.

8 participants