MemoryStream fs = new MemoryStream();
byte[] tmp = null;
// 序列化   
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, obj);
tmp = fs.ToArray();这段代码,在本地运行正常,上传到虚拟主机上出现权限错误,信息如下:Security Exception 
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.请高手指点,谢谢

解决方案 »

  1.   

    kao ,楼上的你怎么又换马甲了。
      

  2.   

    换成这种方式序列化 System.Xml.Serialization.XmlSerializer sml = new System.Xml.Serialization.XmlSerializer(typeof(MyObject));             XmlTextWriter _Formatter = new XmlTextWriter(ms, System.Text.Encoding.Unicode);             sml.Serialize(ms, myObj); 
      

  3.   

    看一下虚拟机是否配置好了,否则我就不知道了,但是帮助lz顶一下
    up
      

  4.   

     public static void SerializeToBinary(object obj, string path, FileMode fileMode)
            {
                using (FileStream fs = new FileStream(path, fileMode))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, obj);
                }
            }public static string SerializeToXml(object obj)
            {
                string xml = "";
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    XmlSerializer serializer = new XmlSerializer(obj.GetType());
                    serializer.Serialize(memoryStream, obj);
                    memoryStream.Seek(0, 0);
                    xml = Encoding.ASCII.GetString(memoryStream.ToArray());
                }            return xml;
            }
        string base64 = "";
       byte[] aryByte = Convert.FromBase64String(base64);
       BinaryFormatter formatter = new BinaryFormatter();
       MemoryStream memoryStream  = new MemoryStream(aryByte,0,aryByte.Length);
       myobject = (MySerialObject)formatter.Deserialize(memoryStream);
       memoryStream.Close();