views:

57

answers:

2

I'm not sure why but in my asp.net project in this code block when i get an exception on GetRequestStream() i cannot move my cursor to another point in the function as i normally do when i get a function.

The reason is Unable to set the next statement to this location. The next statement cannot be set to another function.

Is there something i can do to allow this?

    static public CookieContainer login(string user, string pass)
    {
        var cookie = new CookieContainer();
        var request = (HttpWebRequest)HttpWebRequest.Create(@"https://www.somesite.com/users/login");
        request.CookieContainer = cookie;
        {
            var postData = string.Format("ref=http://www.somesite.com/&username={0}&password={1}", user, pass);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postData.Length;
            using (Stream writeStream = request.GetRequestStream())
            {
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] bytes = encoding.GetBytes(postData);
                writeStream.Write(bytes, 0, bytes.Length);
            }
        }
        var resp = request.GetResponse();
        return cookie;
    }
A: 

You should try putting a breakpoint at the line where the exception occurs.

Another option is to put in a try/catch in your code, and place a breakpoint in the catch.

davogones
The point is so i dont need to. I would like to do the above when an exception occurs and not hit F5 hundreds of times when i run my app every 15mins.
acidzombie24
See my edit (try using a try/catch).
davogones
Better, i am positive that works. But i know in other apps if i have no try/catch i can set the cursor to anywhere in the func. IIRC if i have a try/catch i am always forced to move it to the catch block? good idea but not solving my problem :(
acidzombie24
You're right, I have the same problem... Sometimes it will break at the line where the exception occurred, and sometimes it will break at a function further up the call chain. I've never been able to figure out why it does that. I always just work around it by tracing through the code line by line until I find where the exception is being thrown. Sorry I can't give a better answer.
davogones
A: 

Where are you trying to place the cursor?

The message seems to stay that you are trying to place it in a different funtion. If you want to place the cursor in the calling function, you might be able to move to the return cookie; statement, hit the F10 key 2 times, then move your cursor in the calling function (where you should be by now).

LaustN
I cant even do that. In non asp.net apps i can. It seems other section of code i could do that. I dont know why i cant here and thats what i would like to know. (So yes i am moving within the same func and no i cant move to the return cookie; line like i usually can)
acidzombie24
A qualified guess says that you get to move the cursor in the function that originally threw the exception. For this call, the original exception is deeper in the stack, where you don't (necessarily) have access to the code. Regardless, I would like to see the stack trace of that exception, it would likely provide hints to a specific solution to the coding problem.
LaustN
As davogones says, using try/catch is the proper way of doing it. Consider using very small try/catch block that only hold the one line that you suspect will cause trouble. This should also allow you to move the cursor in small steps + it leaves little doubt which line actually threw the exception.
LaustN