Open chaoslife opened 5 years ago
遇到了 差不多类似的问题 mac打包后 上传文件会报错.
System.Net.HttpListenerException (0x80004005): 由于线程退出或应用程序请求,已中止 I/O 操作。 在 System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size) 在 AliyuProgrammer.Program.MainProcess(IAsyncResult ar)
未经处理的异常: System.Net.HttpListenerException: 企图在不存在的网络连接上进行操作。 在 System.Net.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 size) 在 AliyuProgrammer.Program.MainProcess(IAsyncResult ar) 在 System.Net.LazyAsyncResult.Complete(IntPtr userToken) 在 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 在 System.Net.ListenerAsyncResult.IOCompleted(ListenerAsyncResult asyncResult, UInt32 errorCode, UInt32 numBytes) 在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Sockets.NetworkStream'. at System.Net.WebConnection.BeginRead (System.Net.HttpWebRequest request, System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.AsyncCallback cb, System.Object state) [0x0002b] in <3845a180c26b4889bc2d47593a665814>:0 at System.Net.WebConnectionStream.BeginRead (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.AsyncCallback cb, System.Object state) [0x0017d] in <3845a180c26b4889bc2d47593a665814>:0 at System.Net.WebConnectionStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x00007] in <3845a180c26b4889bc2d47593a665814>:0 at Aliyun.OSS.Common.Internal.WrapperStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00000]
使用的方法为
try { // 下载文件到流。OssObject 包含了文件的各种信息,如文件所在的存储空间、文件名、元信息以及一个输入流。 var obj = client.GetObject(bucketName, objectName); using (var requestStream = obj.Content) { byte[] buf = new byte[1024]; var fs = File.Open(downloadFilename, FileMode.OpenOrCreate); var len = 0; // 通过输入流将文件的内容读取到文件或者内存中。 while ((len = requestStream.Read(buf, 0, 1024)) != 0) { fs.Write(buf, 0, len); } fs.Close(); } Console.WriteLine("Get object succeeded"); } catch (Exception ex) { Console.WriteLine("Get object failed. {0}", ex.Message); }
在Windows下,Unity里使用没有任何问题,在Mac下会报这个错