어떤 이유로이 "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);
}
}
예외는 어떤 행에서 발생합니까? –
'Stream'이 null이라고 추측 할 수 있습니다. 유일한 가능성이있는 것 같습니다. –
죄송합니다. 죄송합니다. 라인을 표시하는 것을 잊어 버렸습니다. – user2288056