【发布时间】:2017-10-06 09:41:54
【问题描述】:
我在以下代码中遇到异常:
(System.IO.MemoryStream) Stream stream = new MemoryStream(fcr.FileContents);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
我将它包装在 Try/Catch 中,并在第二行引发异常:Message = "Parameter is not valid."
我检查了变量stream 的内容。这就是错误所在。展开stream的内容,发现:
Read.TimeOut: 'stream.Read.TimeOut'threw an exception of type
'System.InvalidOperationException'
Write.TimeOut: 'stream.Write.TimeOut' thew an exception of type
'System.InvalidOperationException'
我有两个问题:
- 为什么没有在 Try/Catch 中发现第一个错误?
-
我该如何解决?
using (Stream stream = new MemoryStream(fcr.FileContents)) { System.Drawing.Image img = System.Drawing.Image.FromStream(stream, true, true);
在这里继续崩溃,参数无效。 对象流仍有读写 TimeOut 消息。
【问题讨论】:
-
你在哪里得到错误?在哪两条线?什么是确切的错误消息?顺便说一句,您应该使用使用内存流
-
异常发生在此处显示的第二行代码中。只有当我将鼠标悬停在流上时,才会在第一行代码中显示 TimeOut 错误。
-
什么是
fcr,图片?什么样的? -
fcr 是 png 图片文件
-
两者都不为空。图片存在
标签: c# asp.net-mvc