在 .net core 2.2 中从 .ttf 文件创建和使用自定义字体抛出 CoreClr 错误并重新启动 IIS 应用程序池

问题描述

我正在使用 .net core 2.2 中的自定义字体文件为字符串生成一些图像。当我在本地 PC 上调试时,代码运行良好。但是当我将它部署到 IIS 10 时,它会抛出异常并重新启动应用程序池。

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

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

        return fontFamily;
    }

当我检查 IIS 日志时,也没有记录任何内容。在事件查看器中,我可以看到如下所示的异常。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)