Roslyn: Could not find file "/mscorlib.dll" in a new Android project in Visual Studio 2017

Created on 3 Dec 2017  路  6Comments  路  Source: dotnet/roslyn

Version Used:
Microsoft.CodeAnalysis.CSharp.Scripting 2.4.0
Microsoft Visual Studio Enterprise 2017 Version 15.4.4
Xamarin 4.7.10.38
Xamarin.Android SDK 8.0.2.1

Steps to Reproduce:

  1. Made a new Android project in Visual Studio 2017
  2. Added Microsoft.CodeAnalysis.CSharp.Scripting 2.4.0 from nuget.
  3. I tried the following code object result = await CSharpScript.EvaluateAsync("1 + 2"); Console.WriteLine("result: {0}", result);

Expected Behavior:
result: 3
Actual Behavior:
System.IO.FileNotFoundException: Could not find file "/mscorlib.dll".

Also if it helps the value of typeof(object).Assembly.Location is mscorlib.dll.

Area-Interactive Bug Interactive-ScriptingLogic

All 6 comments

Tagging @tmat
I don't think that's a bug. The scripting API permits adding references. Try adding a reference to mscorlib.
More info on API: https://github.com/dotnet/roslyn/wiki/Scripting-API-Samples

@jcouv I tried the following code snippet:

var result = await CSharpScript.EvaluateAsync("System.Net.Dns.GetHostName()",
    ScriptOptions.Default.WithReferences(typeof(System.Net.Dns).Assembly));

But got this error:
System.IO.FileNotFoundException: Could not find file "/System.dll".

Does this problem repro in an Android emulator, or does it require an Android device?
One thing I'd encourage you to try is enumerating all assemblies visible from your app. If you can find out what assemblies are there, you can add them to your compilation/script.

@jcouv both an emulator and device.

One thing I'd encourage you to try is enumerating all assemblies visible from your app. If you can find out what assemblies are there, you can add them to your compilation/script.
You mean something like this?

var result = await CSharpScript.EvaluateAsync("Sqrt(2)",
    ScriptOptions.Default.WithImports("System.Math",
    "Android.App",
    "Android.Widget",
    "Android.OS",
    "System.Threading.Tasks",
    "System",
    "Microsoft.CodeAnalysis.CSharp.Scripting",
    "Microsoft.CodeAnalysis",
    "Microsoft.CodeAnalysis.Scripting",
    "System.IO",
    "System.Collections.Generic",
    "System.Reflection"));

I get the same crash.

Is there an android sample app anywhere I can have a look at to see what am I doing wrong?

Has a solution been found? I'm trying to do scripting with Xamarin.Android and i'm getting the same error. I've spent time looking for a solution but couldn't find nothing

Was this page helpful?
0 / 5 - 0 ratings