Skip to content

Load compiled assemblies on scripts #26

Description

@duddo

Hi!
I'm trying to load into the evaluator an Assembly produced by CompileAssemblyFromFile, but I can't use the referenced type inside the script. Maybe I'm using a wrong syntaxis?
I put together a simpe example to explain what I'm trying to achieve.

Summer.cs:

using System;

class Summer
{
public int Sum(int a, int b)
{
return a + b;
}
}

Script.cs:

using System;

class Script
{
public int Execute()
{
Summer s = new Summer();
return s.Sum(10, 5);
}
}

Program.cs:

using CSScriptLib;
using System;

namespace CsScript
{
class Program
{
static void Main(string[] _)
{
CSScript.Evaluator.Reset(false); //clear all referenced assemblies

        //compile dll
        string referencedAssemblyName = CSScript.Evaluator.CompileAssemblyFromFile(@".\Summer.cs", @".\Summer.dll");

        //load dll
        CSScript.Evaluator.ReferenceAssembly(referencedAssemblyName);

        //execute
        dynamic script = CSScript.Evaluator.LoadFile(@".\Script.cs");
        int result = script.Execute();
        
        Console.WriteLine(result);
    }
}

}

Thank you!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions