Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

PrivateFontCollection freezes the application and return Error in 'w3wp.exe'

$
0
0

We are creating multiple charts as custom web control dynamically, using the below code. If use system font like 'Arial' (installed font), it creates charts well. But we need to load the font from file, for this we are using PrivateFontCollection.

The Code is:

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);                         }




We tried to dispose the 'PrivateFontCollection' still we have these errors. But this error doesn't happenfrequently.

Please suggest, how do we use 'PrivateFontCollection' in ASP custom webcontrol? 

Thanks


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>