Debug.Assert的似乎没有在工作单 [英] Debug.Assert seems not to work in Mono

查看:131
本文介绍了Debug.Assert的似乎没有在工作单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的C#程序:

 使用系统;使用System.Diagnostics程序
;

命名空间测试
{
类MainClass
{
公共静态无效的主要(字串[] args)
{
调试.Assert(假);
Debug.Fail(失败!);
Console.WriteLine(世界,你好!);
}
}
}

在编译这个使用:

 契-debug -d:DEBUG Main.cs 

,然后运行它:

 单--debug MAIN.EXE 

断言和失败似乎被忽略。输出就是:

 世界,你好! 



我查了计算器等相关的问题,但我无法找到一个解决方案。尤其是该解决方案让在单 - Debug.Assert的不工作不工作。 (更新:更新的解决方案确实工作,见下面的评论)



我用单2.10.5-1在Ubuntu 11.10


< DIV CLASS =h2_lin>解决方案

在单C# - HTTP ://ebsteblog.wordpress.com/2009/05/06/debugassert-and-mono/

从文章

摘录:



...如果您为您的应用程序.config文件,并设置assertuienabled属性为true,则获得相同的对话与.NET ...文件的app.config:

 <?XML版本=1.0编码=UTF-8>?; 
<结构>
<&System.Diagnostics程序GT;
<断言assertuienabled =真/>
< /system.diagnostics>
< /结构>



老答案:C ++评论,如果你没有在命令行中指定-define DEBUG /编译选项



有关调试添加

 将#define DEBUG 

在代码的开头或

 的#define TRACE 

有关的痕迹。



在这里看到的解决办法: http://lists.ximian.com/pipermail /mono-list/2006-December/033774.html



PS:我想这与C ++而不是C#。这可能不是为C#的工作。


Consider the following C# program:

using System;
using System.Diagnostics;

namespace Test
{
        class MainClass
    {
        public static void Main (string[] args)
        {
            Debug.Assert(false);
            Debug.Fail("fail!");
            Console.WriteLine ("Hello World!");
        }
    }
}

When compiling this using:

dmcs -debug -d:DEBUG Main.cs

and then running it with:

mono --debug Main.exe

the assertion and fail seem to be ignored. The output is just:

Hello World!

I checked other related questions on StackOverflow, but I could not find a solution. In particular the solution give in Mono - Debug.Assert does not work does not work. (UPDATE: the updated solution does work, see below comments.)

I use Mono 2.10.5-1 on Ubuntu 11.10.

解决方案

C# on mono - http://ebsteblog.wordpress.com/2009/05/06/debugassert-and-mono/

Excerpt from the article:

...if you create a .config file for your app and set the assertuienabled attribute to true, you get the same dialog as with .NET... File app.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.diagnostics>
        <assert assertuienabled="true" />
    </system.diagnostics>
</configuration>

Old answer: C++ comment if you did not specify -define DEBUG on command line/compile options.

For debug add

#define DEBUG

at the beginning of the code or

#define TRACE

for trace.

See the solution here: http://lists.ximian.com/pipermail/mono-list/2006-December/033774.html

p.s: I tried this with C++ not C#. This may not work for C#.

这篇关于Debug.Assert的似乎没有在工作单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆