簡體   English   中英

C#AccessViolationException

[英]C# AccessViolationException

我正在從C#WPF應用程序將ttf文件安裝到C:/ Windows / Fonts文件夾中。在安裝過程中,我遇到了System.AccessViolation異常。 我的代碼如下:

int result = -1;
            int error = 0;
            var windowsDirectory = Environment.GetEnvironmentVariable("SystemRoot") + "\\Fonts\\";
            var directoryInfo = new DirectoryInfo("../../Assets/Fonts");

            foreach (var file in directoryInfo.GetFiles())
            {
                result = AddFontResource((new FileInfo(windowsDirectory + file.Name)).ToString());
                error = Marshal.GetLastWin32Error();
                if (error != 0)
                {
                    System.Diagnostics.Debug.WriteLine(new Win32Exception(error).Message);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine((result == 0) ? "Font is already installed." :
                                                      "Font installed successfully.");
                }
            }

我該如何解決我的問題

如果異常確實是由於缺少管理員權限而引起的,則您可能需要閱讀本文章,以了解如何為管理員權限設置應用程序配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM