0

The following code runs fine on windows 8.1 machines, but gives a null ref on the AddMemoryFont line all pointers seem valid anyone know why?

PrivateFontCollection myFonts = new PrivateFontCollection();
void CreateFonts(string resource)
{
    // receive resource stream
    Assembly ass = Assembly.GetExecutingAssembly();
    Stream fontStream =
     Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
    System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);
    byte[] fontdata = new byte[fontStream.Length];
    fontStream.Read(fontdata, 0, (int)fontStream.Length);
    Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);
    myFonts.AddMemoryFont(data, (int)fontStream.Length);
    fontStream.Close();
    Marshal.FreeCoTaskMem(data);
}
DaveO
  • 1
  • Sorry not a duplicate, as it does not reach the FreeCoTaskMem line. and removing it and placing the pointer into a list to preserve a ref does not make it step passed the AddMemoryFont Line. Surly there should have to be some sort of confirmation from the poster here to close down a question? else we will end up always having a this and never getting help because someone assumes with out knowledge or asking the originator? – DaveO Sep 30 '15 at 14:03
  • Dave, try following the directions I posted (with code) here > http://stackoverflow.com/a/33171089/3504007 . I just finished this and it works on all controls (finally). The problem with this question is that while it has been asked in various forms, and there are some answers, there were no CORRECT answers and thus asking again really shouldn't be considered a duplicate 'with solution' since no solution was found -- until now. – Kraang Prime Oct 16 '15 at 13:07

0 Answers0