Take the 2-minute tour ×

I am using a scriptEngine someone else wrote, but I need to add the ability to pass in a local type to it.

I modified the code, but when I add my namespace to the string code I get "The type or namespace "MyNamespace" could not be found..."

I found this article, but it shows how to do it with 2 pieces of dynamically generated code, I want to reference some local code.

C# - Referencing a type in a dynamically generated assembly

I assume it is something like this but I don't know the how to get/reference the Metadata file for MyNamespace to use in "ReferencedAssemblies.Add".

source ="using MyNamespace;\r\n" + 
            "namespace UserScript\r\n{\r\nusing System;\r\n" +                        
            "public class RunScript" + count.ToString() + "\r\n{\r\n" + 
            variables + "\r\npublic double Eval()\r\n{\r\ndouble Result = Double.NaN;\r\n" +
            code + "\r\nreturn Result;\r\n}\r\n}\r\n}";
        compiler = new CSharpCodeProvider();

parameters = new CompilerParameters();
parameters.GenerateInMemory = true;
results = compiler.CompileAssemblyFromSource(parameters, source);
share|improve this question

Your Answer



Browse other questions tagged or ask your own question.