Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MattWolf74 opened this issue Jul 13, 2018 · 1 comment

Comments

@MattWolf74
Copy link

MattWolf74 commented Jul 13, 2018

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 tried to add to app.config
`

<PropertyGroup>
  <AutoGenerateBindingRedirects enabled="true"/>
  <GenerateBindingRedirectsOutputType enabled="true"/>
</PropertyGroup>

........`

without success...

Thanks

@jinujoseph jinujoseph modified the milestone: Unknown Jul 23, 2018
@gyurisc
Copy link

gyurisc commented Dec 16, 2018

I am seeing this error in my project too when trying to evaluate a Roslyn script. Any ideas when this will be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants