How to catch, in my program, missing sys dll?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    How to catch, in my program, missing sys dll?

    If I get the error:
    Code:
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
    How would I go about catching that? I have the peice of code that caused the above error in a try / catch block, but it still caused a fatal crash during run time... How do I catch stuff like this??
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The more important question is "Why did you allow it to still cause a fatal crash, if you caught it in a try/catch block?"

    How to catch, in my program, missing sys dll?
    You caught the exception. Why did you not end gracefully instead of trying to continue forward?

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      It had nothing to do with letting the program end gracefully. The program didn't even move to catch block.

      Read what I said. The peice of code that error'ed out, despite being within a try / catch block. DID NOT GET CAUGHT. Besides I wasn't antisipating a missing dll oon the users side. Yes I should account for everything, but in this instance, the program didn't give me a chance to account for it.

      Again. It ignored the try/catch.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Can we see the code for this, please?

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          Code:
          public void Load_ClassData(string c, int id)
          				{
          						if (gd.SelectedClass == c) { return; }
          						else { gd.SelectedClass = c; }
          
          						gd.Discription = new List<string>();
          						gd.Talent = new List<string>();
          
          						gd.Discription.Clear();
          						gd.Talent.Clear();
          
          						// URI = InstallFolder / Version Folder / Using Version / Class Name / .xml
          						// Later will be replaced with GetClassVersion()
          						string uri = _settings[18] + "/wowv/" + "[3.2.2]" + c + ".xml";
          						try  {
          								// +---------------------------------------------------------------------
          								// + Load up Class XML Data
          								// +---------------------------------------------------------------------
          								XDocument doc = XDocument.Load(uri);
          
          								gd.TreeBG = doc.Root.Descendants().Where(x => x.Name == "Class").First().Attribute("bg").Value;
          								gd.TreeIco = doc.Root.Descendants().Where(x => x.Name == "Class").First().Attribute("treeico").Value;
          
          								var qTalent = from x in doc.Root.Descendants()
          														where x.Name == "Talent"
          														select x;
          
          								foreach (XElement x in qTalent)
          								{
          										if (Int32.Parse(x.Attribute("pts").Value) > 0)
          										{
          												// Data = ID / Points / Title / Icon / Requirement (if has one)
          												if (x.LastAttribute.Name == "req") { gd.Talent.Add(x.Attribute("id").Value + "," + x.Attribute("pts").Value + "," + x.Attribute("title").Value + "," + x.Attribute("icon").Value + "," + x.Attribute("req").Value); }
          												else { gd.Talent.Add(x.Attribute("id").Value + "," + x.Attribute("pts").Value + "," + x.Attribute("title").Value + "," + x.Attribute("icon").Value); }
          												// Data = Replace String / Description paragraph
          												if (Int32.Parse(x.Attribute("pts").Value) > 1 && x.Descendants().First().Attribute("replace") != null ) { gd.Discription.Add(x.Descendants().First().Attribute("replace").Value + "]|[" + x.Descendants().First().Value); }
          												else { gd.Discription.Add(x.Descendants().First().Value); }
          										}
          										else
          										{
          												// If Talent is "Empty", has 0 points, no description
          												gd.Talent.Add(x.Attribute("id").Value + "," + x.Attribute("pts").Value);
          												gd.Discription.Add("none");
          										}
          								}
          
          								// +---------------------------------------------------------------------
          								// + Initiate The Calc
          								// +---------------------------------------------------------------------
          								string[] Split_TreeBG = gd.TreeBG.Split(',');
          								string[] Split_TreeIco = gd.TreeIco.Split(',');
          								string[] tdtmp;
          
          								// Init Tree Backgrounds
          								for (int i=0; i < Split_TreeBG.Count(); i++)
          								{
          										try { TCTreePanel[i].BackgroundImage = new Bitmap(GetImage("BGTree", Split_TreeBG[i])); }
          										catch (Exception EX) { TCTreePanel[i].BackgroundImage = null; TCTreePanel[i].BackColor = Color.Black; }
          								}
          
          								// Init Tree Icons
          								try {
          										TCTree1Count.Image = new Bitmap(GetImage("TIcon", Split_TreeIco[0]));
          										TCTree2Count.Image = new Bitmap(GetImage("TIcon", Split_TreeIco[1]));
          										TCTree3Count.Image = new Bitmap(GetImage("TIcon", Split_TreeIco[2]));
          										}
          								catch (Exception EX) {  }
          
          								// Init Talent Icons
          								for (int i=0; i < TIcon.Count(); i++)
          								{
          										tdtmp = gd.Talent[i].Split(',');
          
          										if (tdtmp[1] == "0")
          										{
          												TIcon[i].Visible = false;
          												TIcon[i].Enabled = false;
          										}
          										else
          										{
          												TIcon[i].Enabled = true;
          												TIcon[i].Visible = true;
          												TIcon[i].Image = new Bitmap(GetImage("TIcon", tdtmp[3]));
          										}
          								}
          								for (int i = 0; i < 3; i++) { TCTreePanel[i].Visible = true; }
          						} catch (Exception EX) { MessageBox.Show("Error happened when loading XML Data from\n \"" +uri+ "\"\n Error Message: " + EX.Message); }
          						ResetTalent("All");
          				}
          It was catching (not my system, a friend's) on the XDocument.Load( ) Line at the start of the method.
          Still broke with a missing system dll msg.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            And you're saying the application crashed at line 19 when trying to load the document - rather than jumping to the catch at line 87? Do I understand right?

            Comment

            • Samishii23
              New Member
              • Sep 2009
              • 246

              #7
              Thats what happened. It was a runtime error stated in the 1st post. For some reason the catch didn't. I had the user re-install .Net 3.5 SP1. No more error. But still... It still didn't

              Sigh. The thing should regardless shouldn't it? Or maybe it was a 3.0 bug or something... Besides the try/catch, theres not much else in way of error handling methods are there?

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                I agree it's a weird one. I usually tick the checkbox on the InstallShield creator to require the correct .NET framework be installed before the installer will continue. So I guess I've never run across it.
                [IMGNOTHUMB]http://files.me.com/tlhintoq/njzt9m[/IMGNOTHUMB]

                Comment

                • Samishii23
                  New Member
                  • Sep 2009
                  • 246

                  #9
                  Hmm. Right now I'm not doing anything installer work until I clean it all up and get it all working the right way. But thanks for the idea. I'll look into it when the time comes.

                  Is there a Enviroment value I can check the framework installed version?

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #10
                    Logic tells me there is a way to check, since the installer performs just such a check before continuing. But I would have to jump on Google to see *how* it is done. I would guess you could check for a specific file in System32, or a value in registry.

                    Comment

                    Working...