当前位置: 首页 > 图文教程 > .Net技术 > ADO.NET > Remoting笔记:错误:“由于安全限制,无法访问类型System.RunTime.Remoting.ObjRef”

ADO.NET
ADO.NET:小编谈ADO.NET中窗体的飘动
ADO.NET:利用IC卡制作考勤程序
ADO.NET:小编谈如何实现滚动字幕
Remoting笔记:错误:“由于安全限制,无法访问类型System.RunTime.Remoting.ObjRef”

ADO.NET 中的 Remoting笔记:错误:“由于安全限制,无法访问类型System.RunTime.Remoting.ObjRef”


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 340 ::
收藏到网摘: n/a

原因,有个Serializable的Model,里面有个成员为Image类型。

虽然Image继承了ISerializable,但是Image是abstract类,不能被实例化,因此就无法序列化。

我的解决方法,写的很详细:(C#代码)

把Image类型的成员换成Byte[]。

//把Image转换为Byte[]
System.Drawing.Image img = System.Drawing.Bitmap.FromFile(@"图片文件路径");
System.IO.MemoryStream mStream = new System.IO.MemoryStream();
img.Save(mStream, img.RawFormat);
Byte[] bytes = mStream.ToArray();

//把Byte[]转换为Image
System.IO.MemoryStream mStreamnew = new System.IO.MemoryStream(bytes);
Image imgnew = Bitmap(mStreamnew)