locked
Can't catch DataServiceQueryException. VS2010 will highlight the row.... RRS feed

  • Question

  • I have this piece of code

        public bool Login(string user, string pw)
            {
                je.Credentials = new System.Net.NetworkCredential(user, pw);
                try
                {
                    var gg = je.Cities.Where(s => s.Name == "New-York").FirstOrDefault();

                }
                catch (DataServiceQueryException gg)
                {

                    throw;
                }

                return true;
            }

    My goal is to authenticate users before giving access to the WCF data Service.
    If I start a new VS2010 solution with a new project the code will work, the catch will catch the error 401 Access Denied.
    But, if I use this code in my application solution, the catch will not catch any error and the application crash.

    I have no idea how it works in the new solution and not in the other.
    Wednesday, April 18, 2012 1:22 PM

Answers

  • Well, after spending 2 days I just did a system restore at 3:30. (don't ask why .. have no idea)

    now it works.

    • Marked as answer by xavier_X Thursday, April 19, 2012 9:16 AM
    Thursday, April 19, 2012 9:16 AM

All replies

  • If you change it to catch any Exception instead of just DataServiceQueryException in your application solution, does the behavior change?

    -Ian

    Wednesday, April 18, 2012 4:12 PM
  • No. I didn't manage to catch any exception, even the most basic catch(Exception e)
    Wednesday, April 18, 2012 6:14 PM
  • Hi xavier,

    I think @Ian doesn't mean you should modify your catch but trouble-shooting. Try to change to Exception then run your code to see is if the Catch works.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 19, 2012 8:58 AM
    Moderator
  • Well, after spending 2 days I just did a system restore at 3:30. (don't ask why .. have no idea)

    now it works.

    • Marked as answer by xavier_X Thursday, April 19, 2012 9:16 AM
    Thursday, April 19, 2012 9:16 AM
  • Hi xavier,

    Good News!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 19, 2012 9:17 AM
    Moderator