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

  • Question

  • 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
                                        using(PrivateFontCollection fonts = new
                                                    FontFamily fontFamily = new
    FontFamily(fonts.Families.FirstOrDefault()?.Name, fonts); 
                                                    font = new Font(fontFamily, 8); 
                                        _chart = new
                                        // Chart legent creation 
                                        Legend legend = new Legend 
      BackColor = Color.Transparent, 
      BorderColor = Color.Transparent, 
      LegendStyle = this.LegendStyle, 
      Docking = this.Docking, 
      Font = font, 
      TextWrapThreshold = this.LegendTextWrapThreshold 


    See the error

    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? 


    Friday, September 21, 2018 2:16 PM

All replies

  • Hi vj529992,

    Thank you for posting here.

    Since your question is more related to web, you could post a new thread in ASP.NET forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, September 24, 2018 7:43 AM