Questions tagged [csharpscript]

CSharpScript is a CLR based scripting system which uses the C# programming language.

CSharpScript or CS-Script is a CLR (Common Language Runtime) based scripting system (Script execution engine) which uses ECMA-compliant C# as a programming language. CSharpScript currently targets Microsoft implementation of CLR (.NET 2.0/3.0/3.5/4.0/4.5) with full support on Mono.

Hello.cs

using System;
using System.Windows.Forms;
class Script {
    static void Main() {
        MessageBox.Show("Hello World!");
    }
}

Hosting script engine

dynamic script = CSScript.Evaluator
                         .LoadMethod(@"void SayHello(string greeting) {
                                   Console.WriteLine(greeting);
                               }");
script.SayHello("Hello World!");

Benefits of C# Scripting System:

  • Simple deployment approach
  • Portability
  • Base language is a full featured C# and also supports VB.NET, C++/CLI and J#
  • Easy conversion of any script into application and vice versa
  • Script language is type safe
  • Extensibility
  • Script hosting
  • brings you Dynamic Code Generation

Useful links:

32 questions
1
vote
1 answer

How to use CSharpScript with 'globals' type from a DLL which is dynamically loaded into custom collectible AssemblyLoadContext

Script evaluation code snippet: using (var loader = new InteractiveAssemblyLoader()) { var script = CSharpScript.Create( code: expr, options:…
rn3
  • 11
  • 1
1
vote
1 answer

SharpScript .ss file works to connect to database, but same code doesn't work when served to local web-browser?

I have a SharpScript .ss script file with some small code that polls a database and formats things to display. The output is getting too unruly for command line output so I wanted to generate html and view things like that. Generating the html works…
gakera
  • 3,589
  • 4
  • 30
  • 36
1
vote
1 answer

CSharpScript: Dynamic script parameter names

I'm trying to use Roslyn to execute C# code that is defined by the user at runtime, similar to this example: public class Globals { public int X; public int Y; } var globals = new Globals { X = 1, Y = 2 }; Console.WriteLine(await…
Krid
  • 95
  • 1
  • 11
1
vote
0 answers

How to interrupt user-written script?

Trying to run script (using Roslyn Scripting API): var source = "while(true) { }"; return CSharpScript.EvaluateAsync(source).Result; It will run forever. How to interrupt it? I don't mind using other script engine, though asking for one is…
Sinatr
  • 20,892
  • 15
  • 90
  • 319
1
vote
1 answer

Have placeholders for logical operators in Roslyn's CSharpScript code string

I am using Roslyn's capabilities to create "Expressions" as strings which are code snippets with placeholders. At run-time the engine substitutes the place holders with their values and evaluates the expression. For instance an expression would look…
Nikhil
  • 3,304
  • 1
  • 25
  • 42
0
votes
1 answer

Is there any way Csharp scripting API could infer types of arguments without having to specify it?

I have the following piece of code: string actionString = "(p1,p2)=>p1.HP-=20"; var options = ScriptOptions.Default.AddReferences(typeof(SimplePlayer).Assembly).AddImports("Player"); var script = CSharpScript.Create
0
votes
1 answer

Pass array as input parameter in CSharpScript

I try to run method by CSharpScript. Method: public class TaskSolution { public int[] Calculate(int[] inputValue) { return inputValue; } } I tried this solution: var script = CSharpScript.Create(solution.Code); var input = new…
Sterlukin
  • 15
  • 4
0
votes
0 answers

CSharpScripting variables passed are not

I'm trying to execute a script dynamically, via CSharpScript, following the example here: example public class Feature { public class Params { public TypeA ParamA { get; set; } public TypeB ParamB { get; set; } } …
Yafim Simanovsky
  • 531
  • 7
  • 26
0
votes
3 answers

Roslyn CSharpScript EvaluateAsync Returns False When Statement Should Be True

I am just learning how to use Roslyn and I have a script like this: var id = Guid.NewGuid(); string condition = $@"new List {{ new Guid(""{Guid.NewGuid()}""), new Guid(""{id}"") }}.Any(id => id == new Guid(""{id}""));"; var result =…
ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
0
votes
1 answer

Can get script compiled with CSharpScript (Roslyn)

I'm trying to get a script compiled with Roslyn but whatever I do it keeps complaining about this, at this moment I tried almost everything and have no idea what to try next. This is the error I get : '(11,7): error CS0246: The type or namespace…
Kees
  • 1
  • 2
0
votes
1 answer

Roslyn/CSharpScript and VSCode as editor

I have to give my clients the ability to edit scripts with VS Code. The problem.. when my software call: CSharpScript.EvaluateAsync(code, opt, host); host object, should be passed to the script so that the script can interact with my…
andreat
  • 297
  • 2
  • 15
0
votes
1 answer

Roslyn / CSharpScript - Declare and Initialize Dynamic Variables to use them in script

I am having a requirement to execute C# statement dynamically with a number of variables declared runtime. End-user suppose to declare variables runtime ( of certain types only like int,string,List,List, bool etc. ) and perform…
Mahesh
  • 1
  • 1
0
votes
1 answer

c# scripting Roslyn session not accepting reference

I am trying to execute some arbitrary c sharp script in a c# .net application, but I have tried numerous ways to add an external file reference of an assembly and it never seems to work complaining I am missing the assembly. the code is as follows: …
Stevie187
  • 63
  • 3
0
votes
1 answer

How do I import/add packages to C# script file?

Recently I've been practicing C# and learning the fundamentals, and I found it really cool that I can create a script file with dotnet-script. But I haven't seen much support for it online, so I don't know to what extent I can take these script…
luismir15
  • 19
  • 4
0
votes
1 answer

Runtime MissingMethodException

We're experiencing a weird problem at runtime when running code that uses the CSharpScripting classes. Here a sample code to reproduce the error: [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { try …
Michele mpp Marostica
  • 2,445
  • 4
  • 29
  • 45