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

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?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

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

@ivatih Can you share your 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

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)?

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.

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 😃