1

I have the following code I can't get to work right:

 KeyValuePair<string, object> item =
        (KeyValuePair<string, object>)e.AddedItems[0];

      string str = (string)item.Key;

      switch (str)
      {
          case "?":
              this.NavigationService.Navigate(new Uri("/Shared/About/AboutPage.xaml?appName=Elements",
                UriKind.Relative));
              break;
          default:
              this.NavigationService.Navigate(new Uri("/DetailsPage.xaml?url=" +
                HttpUtility.UrlEncode((item.Value as Element).Url.LocalPath),
                UriKind.Relative));
              break;
      }

I have key/value pairs for an object named 'item' and I would like to make the exception to trigger a different code block if the key value "?" is found. Above I used a switch statement to try to execute another code block if "?" is found as a key, otherwise a default code block is executed. But right now I am getting the following exemption triggered when I run the above code:

// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
    if (System.Diagnostics.Debugger.IsAttached)
    {
        // An unhandled exception has occurred; break into the debugger
        System.Diagnostics.Debugger.Break();
    }
}

I am wondering if anyone can give me a clue as to why this is happening. Any help is appreciated, thanks.

ADDED 12/27/2013:

The code block below is from a file that holds a long list of websites, but the last line is not a website but a file within the program I want called instead.

using System;

namespace ...
{
  public class Data
  {
    public static readonly Element[] Elements = {
        new Element("Hydrogen [H] 1", new Uri("http://chemistry.about.com/od/elementfacts/a/hydrogen.htm")),
        new Element("Helium [He] 2", new Uri("http://chemistry.about.com/od/elementfacts/a/helium.htm")),

        ...

        new Element("? About", new Uri("/Shared/About/AboutPage.xaml?appName=Elements", UriKind.Relative))
    };
  }
}

The last line new Element("? About", new Uri("/Shared/About/AboutPage.xaml?appName=Elements", UriKind.Relative)) is the line that holds the link to the file within the program. The first block of code here with the switch statement is supposed to determine the ? in this line of code but I'm not sure I'm doing it right. The second block of code is what is thrown by the debugger when I test the program.

eaavendano
  • 77
  • 7
  • 1
    What is the exception being thrown? – David Pilkington Nov 29 '13 at 06:03
  • From your code sample, I'm not able to identify an obvious reason, why the code for "?" is not reached if "?" is the key. Please add some more details on what the problem is and the exception that is thrown. – Markus Nov 29 '13 at 10:19
  • when I run the code with the first code block above, the second code block comes up with the 'code' System.Diagnostics.Debugger.Break(); 'code' line of code highlighted. So it's breaking into the 'code' private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e){...} 'code' function. This happens when I click on a tab on the application I'm debugging and the "?" represents one of the tabs. It's supposed to take me to the .../AboutPage.xaml file. The other tabs take me to an external web link represented by the default in the switch statement. – eaavendano Nov 29 '13 at 18:16
  • I am not sure what else I can add. I added a few more details above including the code file that is linked to this part of the code. Thanks. – eaavendano Dec 27 '13 at 22:12

0 Answers0