简体   繁体   English

Visual Studio输出窗口中的消息源

[英]Visual studio source of message in output window

Let's say I have a message in my output window (Showing output from Debug ) 假设我的输出窗口中有一条消息(显示Debug的输出)

Exception thrown: 'System.InvalidOperationException' in mscorlib.dll 抛出异常:mscorlib.dll中的“System.InvalidOperationException”

My application doesn't throw an exception, just displays that message and carries on. 我的应用程序不会抛出异常,只显示该消息并继续。 The exception occurs when I make a call to a method in an imported DLL which is a C++ module (my application is C#). 当我在导入的DLL中调用方法时发生异常,这是一个C ++模块(我的应用程序是C#)。 The method still appears to function correctly in spite of this message appearing. 尽管出现此消息,该方法仍然可以正常运行。

My guess is that that module is handling the exception and then displaying that message, but I want to be sure that this is the case and it's nothing to do how I've imported it or marshalled the data (or that custom marshaller). 我的猜测是该模块正在处理异常,然后显示该消息,但我想确定是这种情况,并且我没有做任何事情来导入它或编组数据(或自定义编组)。

(My code: (我的代码:

[DllImport("theExternalModule.dll", EntryPoint = "ReadData", SetLastError = true)]
[return: MarshalAs(UnmanagedType.U4)]
private static extern UInt32 ReadData([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(JaggedArrayMarshaler))] Int16[][] data,
                                      [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(JaggedArrayMarshaler))] Int16[][] dataOrig,
                                      [MarshalAs(UnmanagedType.U2)] Int16 buffsize,
                                      ref int smpNum);

and

resultCode = ReadData(_buffer, _origBuffer, bufferSize, ref sampleNumber);

(when I step through this line in the debugger, the message is displayed) (当我在调试器中单步执行此行时,将显示该消息)

My question is, is there a way of getting the output window to tell me what module or method caused that message to be displayed? 我的问题是,有没有办法让输出窗口告诉我哪个模块或方法导致显示该消息?

This problem usually happens when you change a collection after an enumerator has been created. 在创建枚举数后更改集合时, 通常会发生此问题。 Your original question don't have enough code to assert that, but you can read about this problem here and here . 您的原始问题没有足够的代码来断言,但您可以在此处此处阅读此问题。

Here's an example (taken from one of the article) that would throw that exception : 这是一个例子(取自其中一篇文章),会引发异常:

List<Book> books = new List<Book>();
books.Add(new Book("The Stand", "Stephen King"));
books.Add(new Book("Moby Dick", "Herman Melville"));
books.Add(new Book("Fahrenheit 451", "Ray Bradbury"));
books.Add(new Book("A Game of Thrones", "George R.R. Martin"));
books.Add(new Book("The Name of the Wind", "Patrick Rothfuss"));

Book newBook = new Book("Robinson Crusoe", "Daniel Defoe");
foreach (var book in books)
{
  if (!books.Contains(newBook))
  {
    books.Add(newBook);  // Throws a InvalidOperationException in mscorlib.dll
  }
}

You may also wish to take a look at the InvalidOperation class on MSDN for further causes. 您可能还希望查看MSDN的InvalidOperation类以了解更多原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Visual Studio 2015输出窗口中筛选自定义消息 - Filter custom message from Visual Studio 2015 output window 写入 Visual Studio 的输出窗口 - Writing to output window of Visual Studio Visual studio显示反汇编窗口并显示一条消息“Source可能已更改” - Visual studio Show disassembly window and shows a message that says “Source might have changed” 如何从visual studio 2013的输出窗口中显示“排除未选择构建此解决方案配置的项目”消息 - How to exclude “Project not selected to build for this solution configuration” message from displaying in output window in visual studio 2013 如何将单独控制台 window 的 output 传递给 Visual Studio output Z05B8C74CBD96FBF2DE4C1A352702? - How to pass output of separate console window to Visual Studio output window? Visual Studio输出窗口不会更新 - Visual Studio Output Window does not update Visual Studio 2015&#39;输出窗口&#39;突出显示效果 - Visual Studio 2015 'Output Window' highlight effect Visual Studio调试窗口条输出 - Visual Studio debug window strips output 输出窗口在Visual Studio隔离Shell上不起作用 - Output Window not working on Visual Studio Isolated Shell Visual Studio中输出窗口没有调试选项 - No debug option for output window in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM