Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
C#
private static string GetDllLocation()
       {
           RegistryKey key = Registry.LocalMachine;
           key = key.OpenSubKey(@"Software\LightScribe");
           if (key == null) throw new DllNotFound("LightScribe Libraries not found");

           return key.GetValue("LsPrintLauncher", string.Empty) as string;
       }
Posted

Apparently this can happen on 64bit machines. As you have .NET 4 (or higher) then have a look at the solution on this stackoverflow post[^]
 
Share this answer
 
Indeed, as documentation says the return value of Microsoft.Win32.RegistryKey.OpenSubKey can be null: http://msdn.microsoft.com/en-us/library/z9f66s0a.aspx[^].

If the key not found, it should be null, all correct. Why it can be a problem? Note that GetValue can also be null, and it does not have to be a string type.

—SA
 
Share this answer
 
Comments
WangLirnRen 27-Jun-13 13:59pm    
hi,Sergey Alexandrovich Kryukov.The key of "RegistryKey key = Registry.LocalMachine;" is null.Can you help me??
Sergey Alexandrovich Kryukov 27-Jun-13 14:01pm    
I already did. If it is null, it should be null. Use Regedit and check up.
—SA
Sergey Alexandrovich Kryukov 27-Jun-13 14:02pm    
Wait a minute... Do you mean that the first line of your method gives null, always?
—SA
WangLirnRen 27-Jun-13 14:27pm    
Yes
Sergey Alexandrovich Kryukov 28-Jun-13 0:27am    
Hm... Maybe solution 2 resolves it...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900