Click here to Skip to main content
14,694,484 members
Home » Discussions » .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionWriting unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper19-Apr-19 15:32
Membersimpledeveloper19-Apr-19 15:32 
AnswerRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz21-Apr-19 7:08
mveGerry Schmitz21-Apr-19 7:08 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper21-Apr-19 17:58
Membersimpledeveloper21-Apr-19 17:58 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 5:36
mveGerry Schmitz22-Apr-19 5:36 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 8:07
Membersimpledeveloper22-Apr-19 8:07 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
Gerry Schmitz22-Apr-19 9:28
mveGerry Schmitz22-Apr-19 9:28 
GeneralRe: Writing unit tests for two methods of the same Service are being called in one method: FluentAssertions Pin
simpledeveloper22-Apr-19 9:55
Membersimpledeveloper22-Apr-19 9:55 
Question“Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 6:52
MemberVictorSotnikov9-Apr-19 6: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 7:15
mveGerry Schmitz9-Apr-19 7:15 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 7:28
MemberVictorSotnikov9-Apr-19 7:28 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz10-Apr-19 6:39
mveGerry Schmitz10-Apr-19 6:39 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
David A. Gray3-May-19 8:33
MemberDavid A. Gray3-May-19 8:33 
GeneralRe: “Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
Gerry Schmitz3-May-19 9:48
mveGerry Schmitz3-May-19 9:48 
Questionregarding the cryptarithmatic code in your website Pin
Member 141248901-Apr-19 5:32
MemberMember 141248901-Apr-19 5:32 
AnswerRe: regarding the cryptarithmatic code in your website Pin
Richard MacCutchan1-Apr-19 5:42
mveRichard MacCutchan1-Apr-19 5: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 8:18
Membersimpledeveloper28-Mar-19 8: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 3:33
professionalEddy Vluggen29-Mar-19 3:33 
QuestionASP.Net 4.5 to ASP.Net core 2.0.1 migration issue of Authentication Pin
geetha naidu24-Mar-19 12:38
Membergeetha naidu24-Mar-19 12:38 
AnswerRe: Data Science with Python environment setup Pin
Gerry Schmitz8-Mar-19 10:23
mveGerry Schmitz8-Mar-19 10:23 
GeneralRe: Data Science with Python environment setup Pin
Richard MacCutchan8-Mar-19 23:10
mveRichard MacCutchan8-Mar-19 23:10 
GeneralRe: Data Science with Python environment setup Pin
Gerry Schmitz9-Mar-19 4:04
mveGerry Schmitz9-Mar-19 4:04 
QuestionWPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace28-Feb-19 5:47
MemberSaved By Grace28-Feb-19 5:47 
AnswerRe: WPF DataGridComboBoxColumn Binding Issue Pin
Gerry Schmitz28-Feb-19 11:59
mveGerry Schmitz28-Feb-19 11:59 
AnswerRe: WPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace28-Feb-19 16:06
MemberSaved By Grace28-Feb-19 16:06 
GeneralRe: WPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace1-Mar-19 10:11
MemberSaved By Grace1-Mar-19 10:11 

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.