简体   繁体   中英

Creating and using custom font from .ttf file in .net core 2.2 throwing CoreClr error and restarting IIS app pool

I am generating some images for strings using custom font files in .net core 2.2. The code works fine while I am debugging in local PC. But when I deploy it to IIS 10, it throws exception and restarts the application pool.

public FontFamily GetFontFamily(byte[] ttfFile)
    {
        FontFamily fontFamily;

        using (var memoryStream = new MemoryStream(ttfFile))
        {
            var streamData = new byte[memoryStream.Length];
            memoryStream.Read(streamData, 0, streamData.Length);
            IntPtr data = Marshal.AllocCoTaskMem(streamData.Length);
            Marshal.Copy(streamData, 0, data, streamData.Length);
            using (var privateFontCollection = new PrivateFontCollection())
            {
                privateFontCollection.AddMemoryFont(data, streamData.Length);
                fontFamily = privateFontCollection.Families[0];
                Marshal.FreeCoTaskMem(data);
            }
        }

        return fontFamily;
    }

Nothing is being logged either when I check the IIS logs. In event viewer I can see the exception as shown below.

在此处输入图像描述

try to add the.ttf mime type by following below steps:

1)Open IIS manager.

2)Select the site from which you are getting an exception.

3)Double-click the mime types feature from the middle pane.

在此处输入图像描述

4)From the Action pane click add and add the below values:

fileExtension=".ttf"

mimeType="application/octet-stream"

Restart iis ever after making changes

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