I am installing a ttf file into my C:/Windows/Fonts folder from my C# WPF application.While installing I am getting System.AccessViolation Exception. My code is below:
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.");
}
}
How do Iresolve my issue