J
jc
For some reason I am getting the following exception when calling
Trace.WriteLine(object value):
"System.InvalidOperationException: Collection was modified; enumeration
operation may not execute."
if (Trace.Listeners.Count > 0)
{
Trace.WriteLine(entry); // line 424
}
-
Here is the stack trace:
********* Exception details: **********
Unexpected exception. ---> System.InvalidOperationException: Collection
was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
at System.Diagnostics.TraceInternal.WriteLine(Object value)
at System.Diagnostics.Trace.WriteLine(Object value)
at MyLogger.Write(LogEntry entry) in MyLogger.cs:line 424
-
If I where to instead do the following, it would work.
So this seems that something in the framework is attempting to modify
the
Trace.Listeners collection:
for (int i = 0; i < Trace.Listeners.Count; i++)
{
TraceListener traceListener = Trace.Listeners;
traceListener.WriteLine(entry);
}
Trace.WriteLine(object value):
"System.InvalidOperationException: Collection was modified; enumeration
operation may not execute."
if (Trace.Listeners.Count > 0)
{
Trace.WriteLine(entry); // line 424
}
-
Here is the stack trace:
********* Exception details: **********
Unexpected exception. ---> System.InvalidOperationException: Collection
was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
at System.Diagnostics.TraceInternal.WriteLine(Object value)
at System.Diagnostics.Trace.WriteLine(Object value)
at MyLogger.Write(LogEntry entry) in MyLogger.cs:line 424
-
If I where to instead do the following, it would work.
So this seems that something in the framework is attempting to modify
the
Trace.Listeners collection:
for (int i = 0; i < Trace.Listeners.Count; i++)
{
TraceListener traceListener = Trace.Listeners;
traceListener.WriteLine(entry);
}