This project has moved. For the latest updates, please go here.

Invalid constructor invocation

May 10, 2014 at 9:58 AM
hi i have an Invalid constructor invocation but all is correct
    var xhr = new XmlHttpRequest();
    
    xhr.OnLoadFinish = function() {
        Console.Info(xhr.ResponseText);
    }; 

    xhr.Open("GET", "http://www.google.de/");
    xhr.Send(null);
what is wrong?

ps. here is the xmlhttprequest class:
public class XmlHttpRequest
    {

        public XmlHttpRequest()
        {
            
        }

        public dynamic OnLoadFinish;
        public dynamic OnSendFinish;

        public string MimeType { get { return _webrequest.MediaType; } set { _webrequest.MediaType = value; } }
        public object ResponseText { get; set; }

        private HttpWebRequest _webrequest;

        public void Open(string method, string url)
        {
            _webrequest = (HttpWebRequest) WebRequest.Create(url);
            _webrequest.Method = method;
        }

        public void Send(object data)
        {
            if(data == null)
            {
                var resp = (HttpWebResponse)_webrequest.GetResponse();
                using (var s = resp.GetResponseStream())
                {
                    ResponseText = new StreamReader(s).ReadToEnd();
                    if (OnLoadFinish != null) OnLoadFinish();  
                }
            }
            else
            {
                using (var s = _webrequest.GetRequestStream())
                {
                    var sw = new StreamWriter(s);
                    sw.Write(data);
                    sw.Flush();
                    if(OnSendFinish != null) OnSendFinish();
                }
            }
        }

    }
Coordinator
May 10, 2014 at 2:55 PM
After we provided a suitable Console object, this code worked perfectly with ClearScript 5.3.11. Are you using an older version?
May 10, 2014 at 6:51 PM
Edited May 10, 2014 at 6:55 PM
i use the latest version

and the Console object is a firebug-console implementation
Coordinator
May 10, 2014 at 8:00 PM
Can you provide more information? Which script engine are you using? How are you exposing XmlHttpRequest to the script engine? How are you loading and executing the JavaScript code?
May 11, 2014 at 7:36 AM
i use JScriptEngine

se.AddHostObject("XmlHttpRequest", new XmlHttpRequest());

i execute with: js.Evaluate(Properties.Resources.Run);
i also tried with execute, but same error
May 11, 2014 at 5:26 PM
in c# works the code correctly
Coordinator
May 11, 2014 at 6:42 PM
Hi furesoft,

You're exposing an object - an instance of the XmlHttpRequest class. For the new operator to work, you need to expose the class itself:
se.AddHostType("XmlHttpRequest", typeof(XmlHttpRequest));
Good luck!
May 11, 2014 at 7:11 PM
oh, my bad

thanks