c# - Javascript Compiler in .Net giving errors -


i have following code:

 dim compiler icodecompiler = new microsoft.jscript.jscriptcodeprovider().createcompiler       dim params new compilerparameters       params.generateinmemory = true        dim res compilerresults = compiler.compileassemblyfromsource(params, textbox1.text.trim)       dim ass assembly = res.compiledassembly       dim instance object = activator.createinstance(ass.gettype("foo"))        dim thismethod methodinfo = instance.gettype().getmethod("findproxyforurl")       dim str(1) string       str(0) = ""       str(1) = ""  messagebox.show(thismethod.invoke(instance, str)) 

trying compiler folowing javascript code:

class foo {

    function findproxyforurl(url, host)          {             alert('test')             return "proxy myproxy.local:8080";         } } 

and getting error on -

 compiler.compileassemblyfromsource(params, textbox1.text.trim) 

{c:\users\me\appdata\local\temp\zfwspah4.0.js(4,65) : error js1135: variable 'alert' has not been declared}

if remove "alert" line works fine. gather because alert "window" object, .net doesn't recognise it. have tried replacing window.alert('') still same error.

how can fix this?

alert function supplied host environments (for instance, browsers have it, servers don't). changing alert window.alert didn't make difference because (on browser) comes same thing. (window property of global object refers global object. alert property of global object refers host-provided function. window.alert same alert same window.window.window.alert. digress...)

you'll have use (and import, or receive function parameter, etc.) whatever mechanism provided host environment in you're going run compiled javascript.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -