CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011

    Object reference not set to an instance of an object.

    Hi, im new to c# and new to this forum.

    Win 7 64bit
    .net 3.5 (using vs2008)

    I found this code online to get the 'UninstallString' from a specific subkey within the registry. I am trying to debug the code but im getting the 'Object reference not set to an instance of an object.' error.

    I broke down the code in order to find where it was giving me the error and its at the point where the code posted below has *** ***.

    Im not really sure how to fix this. I previously put a try and catch but it would still break the program. Any help on this would be appreciated.

    Code Below:

    String AppName = "Abode AIR";

    RegistryKey ReadReg = Registry.LocalMachine
    String[] SubNames = ReadReg.GetSubKeyNames();
    Console.ReadLine(); //Dont mind this line
    for (int i = 0; i < SubNames.Length; i++)
    RegistryKey temp = ReadReg.OpenSubKey(SubNames[i])
    ***if (temp.GetValue("DisplayName").ToString() == AppName)***
    Console.WriteLine("Found it");

    Thanks for your support

  2. #2
    Join Date
    Jun 2008

    Re: Object reference not set to an instance of an object.

    Either temp is null or temp.GetValue("DisplayName") is returning null. You should be checking for null if it is a possible return value.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.