System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.' #28506
I use a Console app (.Net Target Framework 4.7.2) and imported (via Nuget)
Microsoft.CodeAnalysis.CSharp (version 2.8.2) and
Microsoft.CodeAnalysis.CSharp.Scripting (version 2.8.2)
I then try to run the following simple code:
class Program
{
static void Main(string[] args)
{
var directory = @"X:\Algorithmic Trading Static Data\Plugins\ResearchStrategy2";
var scriptCode = File.ReadAllText(directory + "\\ResearchStrategy2.cs");
TestRun(scriptCode);
Console.WriteLine("Press to end");
Console.ReadLine();
}
public static void TestRun(string sourceCode)
{
var script = CSharpScript.Create(
@"public class Test : ConsoleApp2.IRunnable {
public void Run() {
System.Console.WriteLine(""test"");
}
}
return typeof(Test);
", ScriptOptions.Default.WithReferences(Assembly.GetExecutingAssembly()));
script.Compile();
// run and you get Type object for your fresh type
var testType = (Type)script.RunAsync().Result.ReturnValue;
// create and cast to interface
var runnable = (IRunnable)Activator.CreateInstance(testType);
// use
runnable.Run();
Console.ReadKey();
}
public interface IRunnable
{
void Run();
}
}
The following Run-Time error is thrown at
var script = CSharpScript.Create( @"public class Test : ConsoleApp2.IRunnable { public void Run() { System.Console.WriteLine(""test""); } } return typeof(Test); ", ScriptOptions.Default.WithReferences(Assembly.GetExecutingAssembly()));
ERROR:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Inner Exception
FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong and how can I fix this run-time error. Do I need some binding redirections? Which and how?
I use a Console app (.Net Target Framework 4.7.2) and imported (via Nuget) Microsoft.CodeAnalysis.CSharp (version 2.8.2) and Microsoft.CodeAnalysis.CSharp.Scripting (version 2.8.2)
I then try to run the following simple code:
The following Run-Time error is thrown at
var script = CSharpScript.Create( @"public class Test : ConsoleApp2.IRunnable { public void Run() { System.Console.WriteLine(""test""); } } return typeof(Test); ", ScriptOptions.Default.WithReferences(Assembly.GetExecutingAssembly()));
ERROR: System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Inner Exception FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong and how can I fix this run-time error. Do I need some binding redirections? Which and how?
I tried to add to app.config `