2016-03-30 9 views
2

次は私のコードです(C#windowsForm)。プロジェクトを公開しているときに、他のコンピュータでエラー/例外が発生しています。"OlampiadEbtedaee.NeedFunction"の型が例外をスローしました

'OlampiadEbtedaee.NeedFunction'のタイプイニシャライザが例外を送出しました。

メインフォームロードイベントでこのクラスの関数(NeedFunction)を呼び出します。問題は、microsoft.win32を使用しているためですか?または他のコンピュータで登録にアクセスできなかったためですか?

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 
    using Microsoft.Win32; 
    using System.IO; 
    namespace OlampiadEbtedaee 
    { 
public static class NeedFunctions 
{ 
    public static bool IsStringInFile(string fileName, string searchString) 
    { 
     return File.ReadAllText(fileName).Contains(searchString); 
    } 

    //////////////////////////////////////// 
    public static string TaskbarsizeState() 
    { 
     RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", false); 
     String value = myKey.GetValue("TaskbarSizeMove").ToString(); 
     return value; 
    } 

    public static string PaintStatusBarState() 
    { 
     RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Applets\paint\view", false); 
     String value = myKey.GetValue("ShowStatusBar").ToString(); 
     return value; 
    } 

    public static string magnifierState() 
    { 
     RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\ScreenMagnifier", false); 
     String value = myKey.GetValue("ZoomIncrement").ToString(); 
     return value; 
    } 
    public static string taskbarSizeMove = TaskbarsizeState(); 
    public static string paintStatusBarState = PaintStatusBarState(); 
    public static string getMagnifierZoomState = magnifierState(); 



    public static string GetPathOfWallpaper() 
    { 
     string pathWallpaper = ""; 
     RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false); 
     if (regKey != null) 
     { 
      pathWallpaper = regKey.GetValue("WallPaper").ToString(); 

      regKey.Close(); 
     } 
     return pathWallpaper; 
    } 

    public static void CreatePrequires() 
    { 
     Directory.CreateDirectory(@"D:\D"); 
     Directory.Delete(@"D:\D"); 
     Directory.CreateDirectory(@"D:\F"); 
     Directory.CreateDirectory(@"D:\X"); 
    } 


} 

}

答えて

1

あなたの問題は、レジストリキーが存在するかどうかをチェックし、その値にアクセスしない程度で失敗します。 最初にレジストリキーを作成してプロジェクトを実行すると、問題は解決します

+0

おかげで良い方法 – Nelly

0

あなたは、レジストリキーが存在するかどうかをチェックし、その値をアクセスしないでください。

メソッドは静的メンバ変数の初期化子と呼ばれているので、タイプが初期化できないので、起動が

+0

もっと詳しく説明してください。私は何をすべきか? – Nelly

+0

私のラップトップでは問題なく動作しますが、他の人にはエラーが表示されます – Nelly

関連する問題