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.
Cake compiles and runs build script.
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
travis, linux, csharp environment as below.
travis
language: csharp
dotnet: 2.1.504
sudo: required
services:
- docker
before_install:
- export PATH=~/bin:$PATH
script:
- chmod +x build.sh
- ./build.sh
var target = Argument("target", "Default");
Task("Default")
.Does(() =>
{
Information("Hello World!");
});
RunTarget(target);
A hello world cake script in conjunction with the above travis.yml should be enough to repro this issue.
~~~sh
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 .
~~~
It's not exclusive to Travis, I have the same problem on my Ubuntu machine after upgrading to Mono 6.8.
--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
I think the exception is thrown here:
So ParseAssemblyName is returning false. Unfortunately that function is extern, and I'm not able to find its implementation yet.
I think mono/mono#16446 broke this five months ago. It added a check that rejects / characters in assembly names:
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.
... ReferencePaths is empty, at least in my use case.
I have the same issue on Travis. Is there any workaround for this?
Try changing mono: latest to mono: 6.6.0 in your .travis.yml until this is fixed.
Just saw that in the description 馃う鈥嶁檧 . Thanks @HebaruSan , I'm gonna try that.
Hi there, I have the same problem using cake with mono 6.8.0 on circle-ci
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:
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 https://github.com/dotnet/roslyn/pull/39369#issuecomment-545970358).
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.
Is there a timeline for updating cake to use a newer Microsoft.CodeAnalysis.CSharp.Scripting dependency with the roslyn preview that fixes this issue?
https://github.com/mono/mono/issues/18508#issuecomment-577397518
https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting/3.5.0-beta2-final
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.
A version with this fixed is now up on our pre-release NuGet feed
https://dev.azure.com/cake-build/cake/_packaging?_a=package&feed=cake%40Local&package=Cake&protocolType=NuGet&version=0.37.0-alpha0026&view=overview
:tada: This issue has been resolved in version v0.37.0 :tada:
The release is available on:
Your GitReleaseManager bot :package::rocket:
Most helpful comment
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 cakeGood examples in these blog posts: