-5
出於某種原因,這給了我一個「System.NullReferenceException:對象引用未設置爲對象的實例」錯誤。什麼會造成這種情況?C#System.NullReferenceException
public class Font
{
private PrivateFontCollection MyFonts = new PrivateFontCollection();
public Font()
{
string resource = "zig_____";
Stream fontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);//this is the line that causes the error
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);
}
}
異常發生在哪條線上? – 2013-05-06 19:58:29
我猜'流'是空的。似乎是唯一的可能性。 – 2013-05-06 19:59:41
哎呀,對不起,我忘了標記行 – user2288056 2013-05-06 19:59:44