Kestrelhttpserver: [Linux:mono:net451] System.InvalidOperationException: Can not find reference assembly 'Microsoft.CSharp.dll' file for package Microsoft.CSharp

Created on 6 Jul 2016  路  13Comments  路  Source: aspnet/KestrelHttpServer

I am getting the following error since moving from RC2 to 1.0.0

System.InvalidOperationException: Can not find reference assembly 'Microsoft.CSharp.dll' file for package Microsoft.CSharp
  at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths (Microsoft.Extensions.DependencyModel.CompilationLibrary library, System.Collections.Generic.List`1 assemblies) <0x41df48f0 + 0x000f7> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyModel.Resolution.CompositeCompilationAssemblyResolver.TryResolveAssemblyPaths (Microsoft.Extensions.DependencyModel.CompilationLibrary library, System.Collections.Generic.List`1 assemblies) <0x41deea60 + 0x00059> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths () <0x41dee970 + 0x00091> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart+<>c.<GetReferencePaths>b__8_0 (Microsoft.Extensions.DependencyModel.CompilationLibrary library) <0x41dee940 + 0x00017> in <filename unknown>:0 
  at System.Linq.Enumerable+<SelectManyIterator>c__Iterator2`2[TSource,TResult].MoveNext () <0x41ba1710 + 0x00193> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature (IEnumerable`1 parts, Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeature feature) <0x41dee0c0 + 0x00173> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature] (Microsoft.AspNetCore.Mvc.ApplicationParts.TFeature feature) <0x41c8fd60 + 0x000d6> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.GetCompilationReferences () <0x41deddc0 + 0x000f7> in <filename unknown>:0 
  at System.Threading.LazyInitializer.EnsureInitializedCore[T] (System.Threading.T& target, System.Boolean& initialized, System.Object& syncLock, System.Func`1 valueFactory) <0x7f61475c49c0 + 0x000d4> in <filename unknown>:0 
  at System.Threading.LazyInitializer.EnsureInitialized[T] (System.Threading.T& target, System.Boolean& initialized, System.Object& syncLock, System.Func`1 valueFactory) <0x7f61475c4960 + 0x00055> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.get_CompilationReferences () <0x41dedc90 + 0x000e0> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.Compile (Microsoft.AspNetCore.Mvc.Razor.Compilation.RelativeFileInfo fileInfo, System.String compilationContent) <0x41db80d0 + 0x00193> in <filename unknown>:0 
  at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorCompilationService.Compile (Microsoft.AspNetCore.Mvc.Razor.Compilation.RelativeFileInfo file) <0x41d6c280 + 0x001c8> in <filename unknown>:0 
  at (wrapper delegate-invoke) System.Func`2[Microsoft.AspNetCore.Mvc.Razor.Compilation.RelativeFileInfo,Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationResult]:invoke_TResult_T (Microsoft.AspNetCore.Mvc.Razor.Compilation.RelativeFileInfo)
  at Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry (System.String relativePath, System.String normalizedPath, System.Func`2 compile) <0x41d67b40 + 0x003f0> in <filename unknown>:0 
question

Most helpful comment

Oh my goodness my mistake, I completely forgot that Mono is not supported and there is no intent to support mvc on multi platform.

Except on the marketing material off coarse. There mvc runs on everything ranging from toasters to dishwashers.

All 13 comments

Is this running on mono?

Oh my goodness my mistake, I completely forgot that Mono is not supported and there is no intent to support mvc on multi platform.

Except on the marketing material off coarse. There mvc runs on everything ranging from toasters to dishwashers.

Found a workaround for now.

Copy everything in /usr/lib/mono/4.5 into /usr/lib/mono/xbuild-frameworks.

Or, this path should be changed to /usr/lib/mono/4.5 but also somehow include /usr/lib/mono/4.5/Facades so that System.Collections.dll works too.

Therefor, one of these two commits did not work properly.

And using the environment variable DOTNET_REFERENCE_ASSEMBLIES_PATH does not work and won't work because some of the assemblies are in the Facades folder.

@pranavkm
@troydai

Good job men!

It seems that 11908 and 4818 has been resolved. Our Asp.Net Core 1.0.0 app is running perfectly on linux net451 after the hack described below.

Looks like all that is left is this;

We've been using a zipped copy of Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1 to compile net451 on xplat and that's worked well for all of our repos. @pakrym might know if it knows to look for the Facades dir as part of the lookup.

@pranavkm https://github.com/dotnet/cli/blob/dc7bab9e28b44d08bf6136f1c5114bc06584cd47/src/Microsoft.DotNet.ProjectModel/Resolution/FrameworkReferenceResolver.cs#L330 yes, we are.

@pompomJuice you can set reference assemblies location using DOTNET_REFERENCE_ASSEMBLIES_PATH environment variable.

@pranavkm I have tried setting DOTNET_REFERENCE_ASSEMBLIES_PATH but for some reason it is ignored and does not work.

I also cannot find the code that breaks because on vs2015 where I debug the code it ends in kernel32. No idea where the code goes when running on linux. I don't really see any abstraction either.

@pompomJuice - this is what we do in our build scripts - https://github.com/aspnet/KoreBuild/blob/dev/build/KoreBuild.sh#L84-L93 and here's the package we point to http://www.myget.org/F/dnxtools/api/v2/package/NETFrameworkReferenceAssemblies/4.5.1 in case it helps.

@pranavkm Ok I checked those deployment scripts and what I am trying to say is there is a mechanism that fails to return a environment variable in dotnet core that fails on mono/net451:

Microsoft.Extensions.DependencyModel.Resolution.Resolve

The exactl line in question is this one

The code then reverts to this line which in turn results in this path.

Therefor I reiterate that the error is a dotnet core error not a ketrel one and I currently work around the issue with:

ln -s /usr/lib/mono/xbuild-frameworks/.NetFramework /usr/lib/mono/4.5
mv /usr/lib/mono/xbuild-frameworks /usr/lib/mono/xbuild-frameworks.bak
ln -s /usr/lib/mono/4.5 /usr/lib/mono/xbuild-frameworks`
cp /usr/lib/mono/4.5/Facades/*.dll /usr/lib/mono/4.5

@pakrym mentioned that the Facades folder is included, but it does not look like that functionality kicks in either, or at least not on net451. Therefor the last cp of those dlls.

After I did this workaround aspnet.core runs perfectly on linux/docker/mono/net451 without any other hacks. Good job men! We are basically there.

This issue appears to be back for me... .net core 1.0, mono 4.6.1.3 or whatever... the symbolic linking stuff doesnt resolve it. Fails to load microsoft csharp. The new mono xbuild-frameworks dont appear to ever have any dlls installed, but rather relatively reference the 4.5 folder in /usr/lib/mono.

I dont know how to troubleshoot further, but I suspect until .net standard 2.0 or whatever the version thats actually supposed to include more libraries on linux is around, this will continue to be a problem. Any pointers?

.Net Core 1.0 does not need mono. What is the error?

.Net Core 1.0 does not need mono, but many libraries still do. So many developers still forced to use mono.

There's actually this neat package that does some hacking to work around this problem https://www.nuget.org/packages/Microsoft.AspNetCore.Mono/ (which is more of an MVC.Razor problem)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

netcore-jroger picture netcore-jroger  路  7Comments

ayende picture ayende  路  6Comments

chtbof picture chtbof  路  3Comments

neyromant picture neyromant  路  4Comments

fabiobraganet picture fabiobraganet  路  7Comments