gpt4 book ai didi

c# - "OlampiadEbtedaee.NeedFunction"的类型初始化抛出异常

转载 作者:太空宇宙 更新时间:2023-11-03 12:49:04 25 4
gpt4 key购买 nike

以下是我的代码(C# windowsForm)。当我发布我的项目时,在其他计算机上出现错误/异常:

The type initializer for 'OlampiadEbtedaee.NeedFunction' threw an exception.

我在主窗体加载事件中调用此类的函数 (NeedFunction)。问题可能是因为我使用的是 microsoft.win32 吗??还是其他电脑访问registery失败??

  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");
}


}

最佳答案

您的问题是您没有检查注册表项是否存在,也没有访问它们的值。先创建注册表项,然后运行你的项目,你的问题就会解决

关于c# - "OlampiadEbtedaee.NeedFunction"的类型初始化抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36300917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com