调试器在没有任何解释的情况下终止应用程序(在 CryptoStream.ReadByte() 调用上)
编辑:我发现了问题。
我的对象的构造函数正在以写入模式初始化文件流,无论我们是否要加密或解密文件。尽管写入文件流将在解密之前关闭(用于此目的的另一个文件流),但它仍然导致无声崩溃。现在效果很好。
所以它看起来像是一个相当普通的文件访问问题。遗憾的是CryptoStream
没有将其作为异常处理。
感谢您的建议 - 我将看看 ProcDump 和 WinDbg。
我刚刚创建了一个小应用程序来读取和解密本地硬盘上的文件。
Visual Studio 调试器会终止应用程序,根本不提供任何消息或解释。当执行以下代码中的行 read = crypto.ReadByte()
时,就会发生这种情况。
try
{
if (file != null)
{
// the stream that was used for encryption
file.Close();
}
var provider = new DESCryptoServiceProvider();
provider.Key = Key;
provider.IV = Key;
var ict = provider.CreateDecryptor();
var bytes = new List<byte>();
using (var stream = new FileStream(fileName, FileMode.Open))
{
crypto = new CryptoStream(stream, ict, CryptoStreamMode.Read);
var decrypted = new MemoryStream();
Int32 read;
try
{
do
{
read = crypto.ReadByte(); // the application dies here
if (read != -1) bytes.Add(Convert.ToByte(read));
}
while (read != -1);
}
finally
{
// we never get here
decrypted.Close();
}
};
return ASCIIEncoding.ASCII.GetString(bytes.ToArray());
}
catch (Exception x)
{
// we never get here either
crypto.Close();
return x.Message;
}
我尝试过并排除的:
没有抛出异常。我们从不输入
finally
,也不输入catch
。我还启用了抛出异常时中断
,但这没有什么区别。没有任何异常迹象。发布应用程序 (ClickOnce) 并运行它具有相同的效果。
重新启动没有什么区别。
制作文件的副本(以防其他进程阻止对其的访问等)并尝试以相同的方式读取该副本失败。
如果我尝试在“监视”窗口中计算
crypto.ReadByte()
,我会按顺序收到以下消息:该表达式会产生副作用并且不会被计算
;当我刷新它时:
函数评估被中止
当我刷新它或等待几秒钟时:
无法计算表达式。调用的对象已与其客户端断开连接。
并且应用程序已终止,我们返回到 Visual Studio。
这里有什么问题呢?
EDIT: I identified the problem.
The constructor for my object was initializing a file stream in writing mode, whether or not we were about to encrypt or decrypt the file. Even though the writing file stream would be closed before decrypting (another file stream used for that purpose), it was still causing the silent crash. Now it works fine.
So it looks like a rather ordinary file access issue. It's a pitty that CryptoStream
does not handle it as an exception.
Thanks for the suggestions - I'll have a look at ProcDump and WinDbg.
I just created a small application to read and decrypt a file from local HDD.
Visual Studio debugger kills the application without any message or explanation at all. It happens when the line read = crypto.ReadByte()
in the following code is executed.
try
{
if (file != null)
{
// the stream that was used for encryption
file.Close();
}
var provider = new DESCryptoServiceProvider();
provider.Key = Key;
provider.IV = Key;
var ict = provider.CreateDecryptor();
var bytes = new List<byte>();
using (var stream = new FileStream(fileName, FileMode.Open))
{
crypto = new CryptoStream(stream, ict, CryptoStreamMode.Read);
var decrypted = new MemoryStream();
Int32 read;
try
{
do
{
read = crypto.ReadByte(); // the application dies here
if (read != -1) bytes.Add(Convert.ToByte(read));
}
while (read != -1);
}
finally
{
// we never get here
decrypted.Close();
}
};
return ASCIIEncoding.ASCII.GetString(bytes.ToArray());
}
catch (Exception x)
{
// we never get here either
crypto.Close();
return x.Message;
}
What I tried and ruled out:
No exceptions are thrown. We never enter
finally
norcatch
. I also enabledBreak when an exception is thrown
, but it makes no difference. No indication of any exception.Publishing the application (ClickOnce) and running it has the same effect.
Fresh restart makes no difference.
Making a copy of the file (in case if some other process was blocking access to it etc.) and trying to read that copy fails in the same manner.
If I try to evaluate
crypto.ReadByte()
in the Watch window, I'm getting the following messages in that order:This expression causes side effects and will not be evaluated
;when I refresh it:
Function evaluation was aborted
when I either refresh it or just wait a few seconds:
Unable to evaluate the expression. The object invoked has disconnected from its clients.
and the app is terminated, we're back to Visual Studio.
What is the problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些建议:
Some suggestions:
我知道现在回答已经太晚了,但也许它对某人有帮助。我有同样的问题,这个答案帮助我 调试器将在没有任何解释的情况下终止应用程序(在 CryptoStream.ReadByte() 调用上)。
如果您的监视窗口包含错误消息“函数评估已中止”, 这可能意味着显示的属性之一具有无限递归,如下所示:
修复无限递归,问题就会消失:
当使用 Visual Studio 抛出 StackOverflowException 时,您可以通过从菜单栏“调试”中选择来捕获 StackOverflowException -> ; “例外”-> “找到...”->输入“stackoverflow”->检查 System.StackOverflowException 的“抛出” -> “好的”
i know it's so late for answer, but maybe it help some one. i have the same problem and this answer help me Debugger kills the application with no explanation (on a CryptoStream.ReadByte() call)
if Your watch window contains an error message "Function evaluation was aborted." That probably means one of the properties displayed has an infinite recursion, like so:
Fix the infinite recursion and the problem should go away:
You can catch the StackOverflowException when it is thrown using Visual Studio by selecting from the menu bar "Debug" -> "Exceptions" -> "Find..." -> type "stackoverflow" -> check "Thrown" for System.StackOverflowException -> "OK"