Click here to Skip to main content
15,884,388 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 14:32
simpledeveloper19-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
simpledeveloper21-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
simpledeveloper22-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
simpledeveloper22-Apr-19 8:55 
Question“Collection was modified; enumeration operation might not execute” inside System.Data.TypedTableBase<> Pin
VictorSotnikov9-Apr-19 5:52
VictorSotnikov9-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:
..................
C#
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:

C#
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
VictorSotnikov9-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
David 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
Member 141248901-Apr-19 4:32 
AnswerRe: regarding the cryptarithmatic code in your website Pin
Richard MacCutchan1-Apr-19 4:42
mveRichard 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
simpledeveloper28-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
professionalEddy Vluggen29-Mar-19 2:33 
QuestionASP.Net 4.5 to ASP.Net core 2.0.1 migration issue of Authentication Pin
geetha naidu24-Mar-19 11:38
geetha naidu24-Mar-19 11:38 
QuestionMessage Closed Pin
6-Mar-19 21:25
Member 141739196-Mar-19 21:25 
AnswerRe: Data Science with Python environment setup Pin
Gerry Schmitz8-Mar-19 9:23
mveGerry Schmitz8-Mar-19 9:23 
GeneralRe: Data Science with Python environment setup Pin
Richard MacCutchan8-Mar-19 22:10
mveRichard MacCutchan8-Mar-19 22:10 
GeneralRe: Data Science with Python environment setup Pin
Gerry Schmitz9-Mar-19 3:04
mveGerry Schmitz9-Mar-19 3:04 
QuestionWPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace28-Feb-19 4:47
Saved By Grace28-Feb-19 4:47 
AnswerRe: WPF DataGridComboBoxColumn Binding Issue Pin
Gerry Schmitz28-Feb-19 10:59
mveGerry Schmitz28-Feb-19 10:59 
AnswerRe: WPF DataGridComboBoxColumn Binding Issue Pin
Saved By Grace28-Feb-19 15:06
Saved By Grace28-Feb-19 15:06 

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.