c# - Debug.Assert 似乎不适用于 Mono

标签 c# mono

考虑以下 C# 程序:

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!");
        }
    }
}

编译时使用:

dmcs -debug -d:DEBUG Main.cs

然后运行它:

mono --debug Main.exe

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

Hello World!

我在 StackOverflow 上查看了其他相关问题,但找不到解决方案。特别是 Mono - Debug.Assert does not work 中给出的解决方案不起作用。 (更新:更新后的解决方案确实有效,请参阅下面的评论。)

我在 Ubuntu 11.10 上使用 Mono 2.10.5-1。

最佳答案

单声道上的 C# - http://ebsteblog.wordpress.com/2009/05/06/debugassert-and-mono/

文章摘录:

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

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

旧答案:如果您未在命令行/编译选项上指定 -define DEBUG,则使用 C++ 注释。

调试添加

#define DEBUG

在代码的开头或

#define TRACE

用于跟踪。

请在此处查看解决方案:http://lists.ximian.com/pipermail/mono-list/2006-December/033774.html

p.s:我尝试使用 C++ 而不是 C#。这可能不适用于 C#。

关于c# - Debug.Assert 似乎不适用于 Mono,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8245314/

相关文章:

c# - 无法建立连接,因为连接到 Azure IP 时目标计算机主动拒绝

c# - CommandHandler 装饰器依赖

c# - ClientConnectionId 的单声道等效项

c# - 无法理解 .NET 中的后台工作人员

C# Mono Linux 进程输出

.net - Raspberry Pi 上的单声道

c# - 事务 - MSDTC 事务管理器的 WS-AtomicTransaction 协议(protocol)服务 'Version10' 被禁用

c# - 安装windows服务失败: service already exists

c# - 在 Entity Framework 4 中处理对象上下文

c# - Mono 说 int 是 List<dynamic>