PrivateFontCollection冻结应用程序并在w3wp.exe中返回错误

时间:2018-09-21 14:31:32

标签: c# asp.net privatefontcollection

我们使用以下代码动态创建多个图表作为自定义Web控件。如果使用“ Arial”(已安装的字体)之类的系统字体,则可以很好地创建图表。但是我们需要从文件中加载字体,为此,我们正在使用PrivateFontCollection。

代码为:

*protected override void CreateChildControls()
        {
            Font font;
            string strFontFile = @"c:\temp\Source sans pro.ttf";
            using(PrivateFontCollection fonts = new PrivateFontCollection())
            {
                fonts.AddFontFile(strFontFile);
                FontFamily fontFamily = new FontFamily(fonts.Families.FirstOrDefault()?.Name, fonts);

                font = new Font(fontFamily, 8);
            }

            _chart = new System.Web.UI.DataVisualization.Charting.Chart();

            // Chart legent creation
            Legend legend = new Legend
                            {
                                BackColor = Color.Transparent,
                                BorderColor = Color.Transparent,
                                LegendStyle = this.LegendStyle,
                                Docking = this.Docking,
                                Font = font,
                                TextWrapThreshold = this.LegendTextWrapThreshold
                            };

            _chart.Legends.Add(legend);

            this.Controls.Add(_chart);
        }*

See the error image

我们仍然尝试处置“ PrivateFontCollection”,但仍存在这些错误。但是这种错误不会经常发生。 请提出建议,我们如何在ASP自定义网络控件中使用“ PrivateFontCollection”?

谢谢

0 个答案:

没有答案