问题
I have the following segment of code.
var script = CSharpScript.Create("int x = 12;");
var result = await script.RunAsync();
var variable = result.GetVariable("x");
int value = (int)variable.Value;
It crashes on the second line with following:
Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This is a UWP application and I am trying to use the Microsoft.CodeAnalysis.CSharp.Scripting
library. I installed the package through NuGet. The app compiles and deploys, but crashes on the second line of this code.
Obviously, the problem is in the System.Core
DLL which has a conflicting version between the one deployed with my app (4.6) and the one used by the library (4.0). Does anyone have a solution to this? Is there a way to specify a version of the library to be used or the target framework (even though I am using UWP)?
回答1:
By testing on my side, I got the following exception:
System.NotSupportedException: Assembly.Load(byte[], ...) is not supported in AppX
Not the same with yours. I used Microsoft.CodeAnalysis.CSharp.Scripting 2.3.2
Actually scripting APIs can't be used within Universal Windows Applications and .NET Native since the application model doesn't support loading code generated at runtime. Details please reference the "Supported Platforms" section of this article. So that currently you should not be able to use the scripting API for UWP.
来源:https://stackoverflow.com/questions/46478087/using-roslyn-scripting-in-uwp