How to fix 'Operation is not valid due to the current state of the object ' in .NET Azure Function?

%3CLINGO-SUB%20id%3D%22lingo-sub-992036%22%20slang%3D%22en-US%22%3EHow%20to%20fix%20'Operation%20is%20not%20valid%20due%20to%20the%20current%20state%20of%20the%20object%20'%20in%20.NET%20Azure%20Function%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-992036%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20.NET%20Azure%20Function%20executed%20by%20Logic%20Apps%20triggered%20by%20an%20SQL%20connector%20%22When%20an%20item%20is%20created%20V2%22.%20The%20function%20gathers%20data%20from%20multiple%20APIs%20and%20inserts%20the%20data%20into%20a%20SQL%20DB.%20The%20function%20works%20good%20for%20singular%20records%2C%20however%2C%20when%20a%20batch%20of%20records%20is%20inserted%20into%20the%20SQL%20table%20triggering%20the%20function%2C%20then%20the%20function%20breaks%20with%20the%20following%20error%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3EOperation%20is%20not%20valid%20due%20to%20the%20current%20state%20of%20the%20object%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EAccording%20to%20multiple%20threads%20on%20the%20Stack%20Overflow%20(i.e.%20%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F8832470%2Foperation-is-not-valid-due-to-the-current-state-of-the-object-error-during-pos%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F8832470%2Foperation-is-not-valid-due-to-the-current-state-of-the-object-error-during-pos%3C%2FA%3E%20)%2C%20to%20resolve%20the%20problem%20the%20web%20config%20file%20should%20be%20configured%20in%20the%20following%20way%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%26nbsp%3B%20%3CAPPSETTINGS%3E%3C%2FAPPSETTINGS%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3CADD%20key%3D%22%26quot%3Baspnet%3AMaxHttpCollectionKeys%26quot%3B%22%20value%3D%22%26quot%3B2001%26quot%3B%22%3E%3C%2FADD%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E%26nbsp%3B%20%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CP%3E%3C%2FP%3E%3CP%3EIs%20there%20any%20way%20to%20change%20the%20web.config%20file%20of%20an%20Azure%20Function%20App%3F%20Where%20I%20will%20find%20it%3F%20Or%20should%20I%20create%20it%20by%20myself%3F%20Do%20you%20have%20any%20other%20ideas%20on%20how%20to%20resolve%20the%20issue%3F%3C%2FP%3E%3CLINGO-LABS%20id%3D%22lingo-labs-992036%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.Net%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E.Net%20Core%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Function%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eweb%20config%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Visitor

I have a .NET Azure Function executed by Logic Apps triggered by an SQL connector "When an item is created V2". The function gathers data from multiple APIs and inserts the data into a SQL DB. The function works good for singular records, however, when a batch of records is inserted into the SQL table triggering the function, then the function breaks with the following error:

Operation is not valid due to the current state of the object

According to multiple threads on the Stack Overflow (i.e. https://stackoverflow.com/questions/8832470/operation-is-not-valid-due-to-the-current-state-of-the-o... ), to resolve the problem the web config file should be configured in the following way: 

  <appSettings>

      <add key="aspnet:MaxHttpCollectionKeys" value="2001" />

  </appSettings>

Is there any way to change the web.config file of an Azure Function App? Where I will find it? Or should I create it by myself? Do you have any other ideas on how to resolve the issue?

0 Replies