this.result = provider.CompileAssemblyFromSource i.e Object reference not set to an instance of an object
CodeDomProvider provider; CompilerParameters para; CompilerResults result; Assembly assembly; Type jsType; object jsObject; public string Message; public void ShowMessage() { MessageBox.Show(this.Message); } private void button1_Click_1(object sender, EventArgs e) { this.para = new CompilerParameters(); this.para.GenerateInMemory = true; string text = @"class JSSample { var obj; function Main() { obj.Message = 'Hello world!'; obj.ShowMessage(); } }"; this.result = provider.CompileAssemblyFromSource(this.para, text); // I got error here this.assembly = result.CompiledAssembly; this.jsType = assembly.GetType("JSSample"); this.jsObject = Activator.CreateInstance(this.jsType); this.jsType.InvokeMember( "obj", BindingFlags.SetField, null, this.jsObject, new object[] { this }); this.jsType.InvokeMember( "Main", BindingFlags.InvokeMethod, null, this.jsObject, null); } }
CodeDomProvider
jscript
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)