Click here to Skip to main content
14,137,520 members

.NET Framework

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 3:09
adminChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 3:05
adminChris Maunder16-Jul-09 3:05 
QuestionMessage Closed Pin
21-Apr-19 6:53
memberMember 1432178121-Apr-19 6:53 
AnswerRe: 阿萨德群无若群无若无群若 Pin
Richard Andrew x6421-Apr-19 7:32
professionalRichard Andrew x6421-Apr-19 7:32 
AnswerRe: 阿萨德群无若群无若无群若 Pin
Eddy Vluggen21-Apr-19 14:52
mveEddy Vluggen21-Apr-19 14:52 
QuestionPassing Value from XAML to ViewModel Pin
Jassim Rahma20-Apr-19 13:45
memberJassim Rahma20-Apr-19 13:45 
AnswerRe: Passing Value from XAML to ViewModel Pin
Gerry Schmitz21-Apr-19 5:56
mveGerry Schmitz21-Apr-19 5:56 
AnswerMessage Closed Pin
8-May-19 20:03
memberrobermartin8-May-19 20:03 
QuestionWriting unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper19-Apr-19 14:32
membersimpledeveloper19-Apr-19 14:32 
AnswerRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz21-Apr-19 6:08
mveGerry Schmitz21-Apr-19 6:08 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper21-Apr-19 16:58
membersimpledeveloper21-Apr-19 16:58 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 4:36
mveGerry Schmitz22-Apr-19 4:36 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 7:07
membersimpledeveloper22-Apr-19 7:07 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 8:28
mveGerry Schmitz22-Apr-19 8:28 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 8:55
membersimpledeveloper22-Apr-19 8:55 
Question“Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 5:52
memberVictorSotnikov9-Apr-19 5:52 
I have an .NET 4.0 assembly; it is registered in GAC and works as part of a BizTalk “orchestration”.
Sometimes I get the following error - “Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.”. I cannot reproduce it; when I run the same processing of the same data, my assembly does not generate the error in this place.

The error happens when I call ‘.Where(<condition>).ToArray()’ for a datatable object: an object of classd System.Data.TypedTableBase<mydatarowclass>.

Here is the code:
..................
int? setTypeGroupId;
...

return instances.WorkContributors.Where
	(
		c =>
			!c.IsInterestedPartyNoNull()
			&& c.InterestedPartyNo == publisherIpNo
			&& c.SetTypeNo == 1
			&& (c.RecordType == "SPU")
            && c.TypeCode == "E" 
            && (!setTypeGroupId.HasValue ||  
                (setTypeGroupId.HasValue && c.SetTypeGroupID == setTypeGroupId))
	)
	.ToArray();

..................

The object ‘instances’ is a dataset – my class produced from System.Data.DataSet.
The property ‘instances.WorkContributors’ is a datatable: an object of class System.Data.TypedTableBase<mydatarowclass>.
The class MyDataRowClass is produced from System.Data.DataRow.

The call stack after the error was the following:
Collection was modified; enumeration operation might not execute. : System.InvalidOperationException: Collection was modified; enumeration operation might not execute.
at System.Data.RBTree`1.RBTreeEnumerator.MoveNext()
at System.Linq.Enumerable.<castiterator>d__97`1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MyProduct.FileParser.Types.CWR.PWRType.GetPublishers(CWRWorkInstances instances, Nullable`1 setTypeGroupId)
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.ValidatePublisherNumber()
at MyProduct.FileParser.Validation.Concreate.PwrTypeValidation.Validate()
at MyProduct.FileParser.Types.CWR.PWRType.StoreRecord(CWRWorkInstances workInstances, CWRWorkParsingContext context)
at MyProduct.FileParser.Groups.CWR.NWRGroup.StoreGroup(Int32 workBatchID, CWRFileCommonData commonData)
at MyProduct.FileParser.CWRParser.ProcessCWRFile(String fileName, Boolean wait, Boolean deleteFile, String sourceFileName)


I cannot understand why the error happens; and why it happens only sometimes and does not happen on the same processed data again.
The error “Collection was modified; enumeration operation might not execute.” Itself is pretty straightforward for me; but I do not see why it happens in that my code. The error is excepted if a code like this:

foreach (DataRow currRow in _someDataTable.Rows)
{
    if (/*deletion condition*/)
    {
        someDataTable.Rows.Remove(currRow);
    }
}
But my code above just wants to enumerate System.Data.TypedTableBase<mydatarowclass> and convert the result into an array.

Any ideas?
AnswerRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz9-Apr-19 6:15
mveGerry Schmitz9-Apr-19 6:15 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 6:28
memberVictorSotnikov9-Apr-19 6:28 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz10-Apr-19 5:39
mveGerry Schmitz10-Apr-19 5:39 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
David A. Gray3-May-19 7:33
groupDavid A. Gray3-May-19 7:33 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz3-May-19 8:48
mveGerry Schmitz3-May-19 8:48 
Questionregarding the cryptarithmatic code in your website Pin
Member 141248901-Apr-19 4:32
memberMember 141248901-Apr-19 4:32 
AnswerRe: regarding the cryptarithmatic code in your website Pin
Richard MacCutchan1-Apr-19 4:42
protectorRichard MacCutchan1-Apr-19 4:42 
QuestionIs there any way to initialize or set values for this declaration as inline statement private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks; Pin
simpledeveloper28-Mar-19 7:18
membersimpledeveloper28-Mar-19 7:18 
AnswerRe: Is there any way to initialize or set values for this declaration as inline statement private IList<MockData<OnlineRegistration, OnlineRegistration, OnlineRegistration>> _registerMocks; Pin
Eddy Vluggen29-Mar-19 2:33
mveEddy Vluggen29-Mar-19 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190518.1 | Last Updated 9 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid