I have a function which returns a PrivateFontCollection:
Public Shared Function GetCustomFonts() As PrivateFontCollection
Dim result = New PrivateFontCollection
Dim customFontFiles = {"Garamond.TTF", "Garamond-Bold.TTF", "Garamond-Italic.TTF", "EurostileExtended-Roman-DTC.TTF"}
For Each fontFile In customFontFiles
result.AddFontFile(Hosting.HostingEnvironment.MapPath("/Includes/" & fontFile))
Next
Return result
End Function
I then use the function as follows:
Using customFonts = Common.GetCustomFonts()
' Do some stuff here
End Using
I would expect that the files would be released, but they are still locked: I get the following error: 'The action can't be completed because the file is open in System. Close the file and try again.'
Shutting down the website in IIS doesn't help; we have to recycle the app pool for it to release.
Can anyone advise on how to use PrivateFontCollection in such a way that the files are released inbetween uses?