简体   繁体   English

PrivateFontCollection.AddFontFile()引发通用GDI +错误异常

[英]PrivateFontCollection.AddFontFile() throws generic GDI+ error exception

Adding a private Font works fine on my local dev machine with Windows 10 Pro. 在Windows 10 Pro的本地开发机器上添加私有字体效果很好。 However on Windows Server 2012 R2 the very same code results in the following error: 但是,在Windows Server 2012 R2上,完全相同的代码导致以下错误:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误。 at System.Drawing.Text.PrivateFontCollection.AddFontFile(String filename) 在System.Drawing.Text.PrivateFontCollection.AddFontFile(字符串文件名)

var privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("Roboto-Regular.ttf");

When I delete the file it results in a NotFoundException, so the file path has to be right. 当我删除文件时,它会导致NotFoundException,因此文件路径必须正确。 I ensured that every user has every possible permission on the file. 我确保每个用户都对该文件拥有所有可能的权限。 (I found out that if I deny every permission on my local win 10 machine the same "generic error" occurs - so it might be a permission problem) (我发现,如果我拒绝本地win 10机器上的每个权限,都会发生相同的“一般错误”-因此可能是权限问题)

Has anybody a solution for this problem? 有没有人解决这个问题? Could it be possible that the service user on the productive machine lacks some other rights that are necessary for "installing" private fonts? 生产机器上的服务用户是否可能缺少“安装”私有字体所需的其他某些权限? Maybe the font gets installed to a specific directory which is not allowed - but I could not find out where this would be. 也许字体被安装到了不允许的特定目录中-但我无法确定其位置。 Please help me with this very self explaining "generic error". 请帮助我自我解释“一般错误”。

It seems to have been a problem with not using an absolute path. 不使用绝对路径似乎是一个问题。 Didn't think of it at first, because deleting the file resulted in an explicit FileNotFound. 起初没有想到,因为删除文件会导致显式FileNotFound。 Using an absolute path did the trick. 使用绝对路径可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM