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

How to load and get assemblies references from HOST #113

Closed
NothingFaceX opened this issue May 9, 2018 · 1 comment
Closed

How to load and get assemblies references from HOST #113

NothingFaceX opened this issue May 9, 2018 · 1 comment
Labels

Comments

@NothingFaceX
Copy link

Hi , for example I have MessageX.dll has a class that show a messagebox .
this dll is embedded in my app by fody Costura , it loaded to my host .
how can I added to my script ?


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string code = @"        //
                                    using System.Windows.Forms;
                                    using MessageX;

                                     public class Script
                                     {
                                         public void SayHello()
                                         {
                                            Class1.saysomething();
                                         }
                                     }";
            CSScript.Evaluator.GetReferencedAssemblies(code);
            dynamic script = CSScript.Evaluator
                                    .LoadCode(code);
            script.SayHello();
        }

Error I get :
error CS0246: The type or namespace name `MessageX' could not be found. Are you missing an assembly reference?

@oleg-shilo
Copy link
Owner

The appcomain assemblies are supposed to be referenced by default:

public class ExternalClass // dynamictest3.Program.ExternalClass
{
    public static void SayHello()
    {
        Console.WriteLine("Hello...");
    }
}

static void Issue_113()
{
    using (SimpleAsmProbing.For(Assembly.GetExecutingAssembly().Location.GetDirName()))
    {
        dynamic script = CSScript.RoslynEvaluator
                                 .LoadCode(@"using System.Windows.Forms;
                                             using dynamictest3;
                                                     
                                             public class Script
                                             {
                                                 public void SayHello()
                                                 {
                                                     Program.ExternalClass.SayHello();
                                                 }
                                             }");

        script.SayHello();
    }
}

Though from your code it's not clear which engine you are using. It looks like Mono since it is the default engine of CSScript.RoslynEvaluator.

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

No branches or pull requests

2 participants