1

I have a C# method which contains code like the following:

try
{
  // Do whatever
}
catch (Exception2 ex)
{
  // Handle exception 1
}
catch (Exception2 ex)
{
  // Handle exception 1
}
catch (Exception3 ex)
{
  // Handle exception 3
}

When I try to debug it, I could place breakpoints normally. However, when one of the catch statements uses the when keyword, like:

catch (ArgumentOutOfRangeException ex) when (ex.Message.StartsWith("Whatever message"))

no debugging symbol is loaded for that method and I cannot get the debugger to break inside it. Breakpoints inside the method are displayed like:

No debugging symbols loaded for method

Any idea why this is happening? I am using VS2015 Update 3.

UPDATE: One of the comments asked me to show more code, but I literally ended up simplifying my code to the following:

using (var model = ContentInventoryModel.Create())
{
  try
  {
    Console.WriteLine("test");
  }
  catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains("This email group can"))
  {
  }
}

With this code, no symbols are not generated for the method and so I cannot put a break point, say, at Console.WriteLine statement. By the time I remove the when keyword, symbols get generated and I can put a break point at Console.WriteLine statement.

It might be worth mentioning that I am debugging through ReSharper's NUnit Test Runner.

Rafid
  • 18,991
  • 23
  • 72
  • 108
  • Are you debugging with full debug symbols (ie. are is the configuration set to debug or to release or maybe something custom)? – Igor Oct 28 '16 at 17:32
  • Can you show more code please?I suspect that debugger see that code is unreachable and give you the worning – volkinc Oct 28 '16 at 20:23
  • @Igor yes, full debug symbols for sure. – Rafid Oct 28 '16 at 20:29
  • @volkinc see my edit. – Rafid Oct 28 '16 at 20:55
  • Can you set breakpoints in the try section? – BenPen Oct 28 '16 at 21:03
  • @BenPen, no I cannot. – Rafid Oct 28 '16 at 21:44
  • Have you looked at this question: http://stackoverflow.com/questions/2155930/fixing-the-breakpoint-will-not-currently-be-hit-no-symbols-have-been-loaded-fo?noredirect=1&lq=1 It sounds like you might be trying to set breakpoints before any of the symbols are loaded, and that question should solve it. – BenPen Oct 28 '16 at 21:50
  • @BenPen yes, I have seen that. No actually, other symbols from the even the same file are loaded and I could set break points; it is literally just that method, and only when I use the "when" keyword. – Rafid Oct 28 '16 at 21:51
  • I'm with @Rafid, check for statements that always exit, ifs that are demonstrably not true I guess. – BenPen Oct 28 '16 at 21:54
  • The code actually does run correctly and calls made inside the method do actually get called, so it is not a matter of conditions statements that always exit or something like that. – Rafid Oct 29 '16 at 05:50

0 Answers0