Roslyn: Could not load file or assembly 'System.Reflection.Metadata'

Created on 13 Aug 2016  路  17Comments  路  Source: dotnet/roslyn

Version Used:

  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.1" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net461" developmentDependency="true" />

Steps to Reproduce:
No idea.

Actual Behavior:

Getting this exception occasionally:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in csc.exe

Additional information: Could not load file or assembly 'System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
>   csc.exe!Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.RunLocalCompilation(string[] arguments, Microsoft.CodeAnalysis.CommandLine.BuildPaths buildPaths, System.IO.TextWriter textWriter)    Unknown
    csc.exe!Microsoft.CodeAnalysis.CommandLine.BuildClient.RunCompilation(System.Collections.Generic.IEnumerable<string> originalArguments, Microsoft.CodeAnalysis.CommandLine.BuildPaths buildPaths, System.IO.TextWriter textWriter)  Unknown
    csc.exe!Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(System.Collections.Generic.IEnumerable<string> arguments, System.Collections.Generic.IEnumerable<string> extraArguments, Microsoft.CodeAnalysis.CommandLine.RequestLanguage language, Microsoft.CodeAnalysis.CommandLine.CompileFunc compileFunc, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader analyzerAssemblyLoader)  Unknown
    csc.exe!Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(string[] args, string[] extraArgs)   Unknown
    csc.exe!Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(string[] args)   Unknown

Any ideas?

Area-Interactive Need More Info

All 17 comments

That's a very strange error to be occurring sporadically. That error seems to indicate that System.Reflection.Metadata is simply missing. If so then that should always fail or always succeed.

This is going to need a bit of diagnosing on your machine because it definitely doesn't reproduce locally:

  1. Can you verify that System.Reflection.Metadata exists next to csc.exe
  2. Can you enabe load failure tracking in fuslogvw. Next time the load fails it should have some detailed info on what went wrong and that will give us another item to go on.

Closing for now as we're unable to reproduce this. If you're able to get the above information please let us know and we'll take a look.

I think I was able to reproduce this. I had project A which has a dependency on project B. Project B contains all the code to execute the script which is called from project A. When installing the NuGet package from project B, everything will go ok, however when adding a reference on project B from project A, only the Roslyn (compiler packages) dll will get copied to bin folder of project A, hence the FileNoTFoundException (it seems that Roslyn is looking for those packages in the bin folder). Disclaimer: a primer here :)

I have same problem as @eligu. I Have 2 projects A (contain logic to execute script) and B (console app with reference to A). When B want to execute logic from A i get this exception:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Agito.Hrm5.ScriptingEngine.ConsoleUI1.exe

Additional information: Could not load file or assembly 'System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Can you elaborate a bit more on what is happening here? I'm unclear what script is getting executed. Is it a C# script (csi file)?

Do you have a skeleton project / repro you can share out?

I found out that I needed to add this two references to project B to use any functionality from project A:

System.Reflection.Metadata
System.Collections.Immutable

Shouldn't all dependencies come with project A (library project)?

Hello i have a similar problem. Two projects, one of them wcf service

[ServiceContract]
    public interface IScriptService
    {
        [OperationContract]
        void ExecuteScript(string code);

        [OperationContract]
        string GetString(string code); //for check that service works well

    }
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false, IncludeExceptionDetailInFaults = true)]
    public class ScriptService : IScriptService
    {
        public void ExecuteScript(string code)
        {
            var a = CSharpScript.Create(code);
            var b = a.RunAsync();
        }
}

When i execute it in client it's throw exception
System.IO.FileNotFoundException
When I execute without any service just script it's works well in both projects.

i use: microsoft.codeanalysis version 1.3.2
microsoft.codeanalysis.scripting version 1.3.2

Please help)))) it's very important for me. May be I doing something wrong?

CC @tmat as that looks like a scripting issue above.

@ivatih Can you share your project?

https://github.com/ivatih/Pad

I have 3 projects:
1) Hosting (lib) just ScriptHost class
2) Console Application: Run scripthost, create host and his endpoint
3) Client, when push the button client try start Console Application with host

tmat, thanks for help)

Was it ever fixed?

Could it be related to 4.5.2 / 4.6 versioning?

We're getting it on Visual Studio 2015 + Roslyn, with MSDN subscription for whole of the team. If you need anything specific to investigate please get back and we'll pass it on.

What exactly is System.Reflection.Metadata, and how is it loaded? Please at least give a bit more context how to investigate the issue (if you can't solve the problem).

I'll take a look today at https://github.com/ivatih/Pad

I'm not seeing any issues. I opened the solution, built, run the app. I only saw some XAML errors like:

System.Windows.Data Error: 17 : Cannot get 'Childrens' value (type 'ObservableCollection`1') from '' (type 'DocumentViewModel'). BindingExpression:Path=Childrens; DataItem='DocumentViewModel' (HashCode=64320678); target element is 'TreeViewItem' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') TargetInvocationException:'System.Reflection.TargetInvocationException: Property accessor 'Childrens' on object 'LinqPad.ViewModels.DocumentViewModel' threw the following exception:'Could not find a part of the path 'C:\Users\Ivan\Documents\LinqPad\Samples'.' ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\Ivan\Documents\LinqPad\Samples'.

Yes, this now work, because I removed part of the project with this issue. I had to quickly pass project. But the issue has not been resolved, may be I can reproduce problem!? My apologies.

Hello, very strange, I have the same issue.

I updated the compiler via nuget.. and many dlls..

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Data". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.UI". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MadsTorgersen picture MadsTorgersen  路  3Comments

glennblock picture glennblock  路  3Comments

marler8997 picture marler8997  路  3Comments

OndrejPetrzilka picture OndrejPetrzilka  路  3Comments

DavidArno picture DavidArno  路  3Comments