[英]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.