您的位置:首页 > 编程语言 > C#

VisualStudio2005 用C# 写的程序,Release版本和Debug版本有什么区别,大家讨论一下好吗?

2007-04-27 11:36 549 查看
产品里部分功能用dotnet 写的。某个函数有时候莫名的出现null reference异常
在测试服务器上,只能用windbg跟踪。
为了验证自己的一些想法,做了个例子,但结果很奇怪。

private void button1_Click(object sender, EventArgs e)
{
Test.Fun1();
MessageBox.Show("aaa");
}
namespace Debug
{
public class Test
{
public static void Fun1()
{
System.Windows.Forms.MessageBox.Show("In Test.Fun1()");
Fun2();
string str = null;
int length = str.Length;
}

private static void Fun2()
{
Fun3();
}

private static void Fun3()
{
Fun4();
}

private static void Fun4()
{
string str = null;
int length = str.Length;
}
}
}

VisualStudio2005 下Release版本
这个程序执行不会出错,没有抛异常信息。这是为什么呢

还有用WinDbg 跟踪
明明已经执行到这句了
System.Windows.Forms.MessageBox.Show("In Test.Fun1()");
怎么还得到这样的信息呢
0:005> !name2ee Debug.exe Debug.Test.Fun1
Module: 00972c14 (Debug.exe)
Token: 0x0600000d
MethodDesc: 00976438
Name: Debug.Test.Fun1()
Not JITTED yet. Use !bpmd -md 00976438 to break on run.

Debug版本一切正常,跟预期的是一样的

(82c.7fc): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00976ce0 ebx=00000000 ecx=7b5ecb10 edx=0012efd4 esi=012db9f8 edi=00000000
eip=00f603c8 esp=0012eff4 ebp=0012f0a8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
00f603c8 8b7708 mov esi,dword ptr [edi+8] ds:0023:00000008=????????
0:000> !name2ee Debug.exe Debug.Test.Fun1
Module: 00972c14 (Debug.exe)
Token: 0x0600000d
MethodDesc: 00976cc8
Name: Debug.Test.Fun1()
JITTED Code Address: 00f60318
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐