红俊's profile蝈蝈俊的共享空间PhotosBlogListsMore Tools Help

Blog


    August 29

    代码优化出的问题

    今天碰到了一个超级怪异的问题, Visual Studio 调试一段代码时,如下图:监视窗口显示这个变量有值,但是代码却执行到这个变量无值的逻辑中了。

    为了这个问题,我简直疯了。

    后来看到其中一些变量的察看时,会报错误

    Cannot obtain value of local or argument 'oo' as it is not available at this instruction pointer, possibly because it has been optimized away.

    在装配脑袋的提醒下,觉得可能是Visual Studio的代码优化导致了这个问题。

    取消编译时候的代码优化。 再Debug,就没有这个问题。

    竟然是代码优化导致了这个让我困扰了一下午的问题。

    代码优化取消在下面位置, 取消 Optimize code 之前的 CheckBox 即可。黄线上面的选项

    August 28

    Debug方式调试GAC中部署的程序

    我们在调试GAC中部署的程序时候,很可能碰到下面的报告:

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    The following module was built either with optimizations enabled or without debug information:

    C:\Windows\assembly\GAC_MSIL\CSDN.Community.TopicListDataCenter.EnterpriseComponents\2.5.1.23407__cdde601ea7585548\aaa.dll

    To debug this module, change its project build configuration to Debug mode. To suppress this message, disable the 'Warn if no user code on launch' debugger option.
    ---------------------------
    确定  
    ---------------------------

    这是因为VS开发工具在C:\Windows\assembly\GAC_MSIL\CSDN.Community.TopicListDataCenter.EnterpriseComponents\目录下没有找到aaa.pdb调试符号文件。当然这个目录是GAC的目录,不可能有的。

    如何解决,最笨的方法是吧 PDB 文件 Copy 到那个目录去。

    我这里要说的解决方法当然不是这样的了。而是如下:

    在Visual Studio 的调试属性中去掉 Enable Just My Code(Managed only)

    这时候我们再去调试就不会出现上述提示文本了。也不会找不到 PDB文件了。一切都OK了。

    我们在Modules窗口也可以看到成功加载了正确位置的pdb文件。

     

     

    参考资料:

    You Don't Need to Copy PDB Files to Debug in the GAC!
    http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=23

    August 07

    点燃主火炬的火炬手我猜是 “体操王子”李宁。 采用方式类似凌波微步或者叫凤回巢的方式飞过去。

    写个非技术的。

    奥运会点燃主火炬的我猜是“体操王子”李宁。

    点火方式我猜会吊钢丝,类似中国功夫的凌波微步,或者叫凤回巢的方式飞过去。

    李宁的照片,看起来老了。