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

    Pertanyaan

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


    

    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? 

    Thanks


    21 September 2018 14:16

Semua Balasan

  • 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.

    https://forums.asp.net/

    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,

    Wendy


    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 MSDNFSF@microsoft.com.

    24 September 2018 7:43