简体   繁体   中英

PrivateFontCollection.AddFontFile() throws generic GDI+ error exception

Adding a private Font works fine on my local dev machine with Windows 10 Pro. However on Windows Server 2012 R2 the very same code results in the following error:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Text.PrivateFontCollection.AddFontFile(String filename)

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. 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)

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. Using an absolute path did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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