Execution seemingly halts for no reason when using Dictionary.add within a foreach loopHow do you get the index of the current iteration of a foreach loop?In .NET, which loop runs faster, 'for' or 'foreach'?Foreach loop, determine which is the last iteration of the loopC# Dictionary Return TypeTimeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminatedIs there a reason for C#'s reuse of the variable in a foreach?StreamReader inside foreach loop of CheckedItemsError when using foreach on dictionary which contains objects as valueNullReferenceException on foreach loop when list is populated (not null)Linq foreach loops once then throws error

iPad or iPhone doesn't charge until unlocked?

What is "super" in superphosphate?

Why should care be taken while closing a capacitive circuit?

Are unaudited server logs admissible in a court of law?

How do neutron star binaries form?

Control GPIO pins from C

Hiker's Cabin Mystery | Pt. XV

Installing the original OS X version onto a Mac?

How can I train a replacement without letting my bosses and the replacement knowing?

Starships without computers?

Polar contour plot in Mathematica?

From France west coast to Portugal via ship?

Are there categories whose internal hom is somewhat 'exotic'?

Why is the name Bergson pronounced like Berksonne?

Earliest evidence of objects intended for future archaeologists?

Is "stainless" a bulk or a surface property of stainless steel?

Number of matrices with bounded products of rows and columns

Why doesn't mathematics collapse down, even though humans quite often make mistakes in their proofs?

Does git delete empty folders?

Do banks' profitability really suffer under low interest rates

Indirect speech - breaking the rules of it

Can sulfuric acid itself be electrolysed?

Why do aircraft leave the cruising altitude long before landing just to circle?

Would it be illegal for Facebook to actively promote a political agenda?



Execution seemingly halts for no reason when using Dictionary.add within a foreach loop


How do you get the index of the current iteration of a foreach loop?In .NET, which loop runs faster, 'for' or 'foreach'?Foreach loop, determine which is the last iteration of the loopC# Dictionary Return TypeTimeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminatedIs there a reason for C#'s reuse of the variable in a foreach?StreamReader inside foreach loop of CheckedItemsError when using foreach on dictionary which contains objects as valueNullReferenceException on foreach loop when list is populated (not null)Linq foreach loops once then throws error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















This is really puzzling me as I can't figure out any apparent reason for execution of my method to come to a sudden halt.



The method I have below is relatively simple, all I am doing is iterating through a collection of objects and adding some data to a new Dictionary based on the current data.



public Dictionary<string, string> MapValidationErrorToIdentifiers(List<ErrorField> errors)

var mappings = new Dictionary<string, string>();

foreach (var error in errors)

string identifier;
if (error.CollectionIndex == "")

identifier = error.Section + "-" + error.FieldName.Replace(" ", "-");

else

identifier = error.Section + "-" + (error.CollectionIndex + 1) + "-" + error.FieldName.Replace(" ", "-");

identifier = identifier.ToLower();
mappings.Add(identifier, error.Message);


return mappings;



The input object List<ErrorField>, is comprised of ErrorField objects, which are simple DTO objects.



public class ErrorField

public string FieldName get; set;
public string Section get; set;
public string CollectionIndex get; set;
public string Message get; set;



During testing of this method in one instance the errors input object contained 12 ErrorField objects, the foreach completed one iteration successfully, and a key-value pair was added to the dictionary. Then on the second iteration the method worked up until the mappings.Add(identifier, error.Message); call, at which point the debugger stops entirely and no further execution occurs.



The strange thing here is that execution just stops, no exceptions or errors are thrown. This method is part of a larger ASP.NET project, and this method is used within a controller. When the execution halts it causes my end-point to return 404. Not sure if that is relevant or not.










share|improve this question
























  • Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

    – CodeCaster
    Mar 27 at 14:22











  • When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

    – Treeline
    Mar 27 at 14:27











  • @CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

    – Jake12342134
    Mar 27 at 16:26

















0















This is really puzzling me as I can't figure out any apparent reason for execution of my method to come to a sudden halt.



The method I have below is relatively simple, all I am doing is iterating through a collection of objects and adding some data to a new Dictionary based on the current data.



public Dictionary<string, string> MapValidationErrorToIdentifiers(List<ErrorField> errors)

var mappings = new Dictionary<string, string>();

foreach (var error in errors)

string identifier;
if (error.CollectionIndex == "")

identifier = error.Section + "-" + error.FieldName.Replace(" ", "-");

else

identifier = error.Section + "-" + (error.CollectionIndex + 1) + "-" + error.FieldName.Replace(" ", "-");

identifier = identifier.ToLower();
mappings.Add(identifier, error.Message);


return mappings;



The input object List<ErrorField>, is comprised of ErrorField objects, which are simple DTO objects.



public class ErrorField

public string FieldName get; set;
public string Section get; set;
public string CollectionIndex get; set;
public string Message get; set;



During testing of this method in one instance the errors input object contained 12 ErrorField objects, the foreach completed one iteration successfully, and a key-value pair was added to the dictionary. Then on the second iteration the method worked up until the mappings.Add(identifier, error.Message); call, at which point the debugger stops entirely and no further execution occurs.



The strange thing here is that execution just stops, no exceptions or errors are thrown. This method is part of a larger ASP.NET project, and this method is used within a controller. When the execution halts it causes my end-point to return 404. Not sure if that is relevant or not.










share|improve this question
























  • Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

    – CodeCaster
    Mar 27 at 14:22











  • When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

    – Treeline
    Mar 27 at 14:27











  • @CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

    – Jake12342134
    Mar 27 at 16:26













0












0








0








This is really puzzling me as I can't figure out any apparent reason for execution of my method to come to a sudden halt.



The method I have below is relatively simple, all I am doing is iterating through a collection of objects and adding some data to a new Dictionary based on the current data.



public Dictionary<string, string> MapValidationErrorToIdentifiers(List<ErrorField> errors)

var mappings = new Dictionary<string, string>();

foreach (var error in errors)

string identifier;
if (error.CollectionIndex == "")

identifier = error.Section + "-" + error.FieldName.Replace(" ", "-");

else

identifier = error.Section + "-" + (error.CollectionIndex + 1) + "-" + error.FieldName.Replace(" ", "-");

identifier = identifier.ToLower();
mappings.Add(identifier, error.Message);


return mappings;



The input object List<ErrorField>, is comprised of ErrorField objects, which are simple DTO objects.



public class ErrorField

public string FieldName get; set;
public string Section get; set;
public string CollectionIndex get; set;
public string Message get; set;



During testing of this method in one instance the errors input object contained 12 ErrorField objects, the foreach completed one iteration successfully, and a key-value pair was added to the dictionary. Then on the second iteration the method worked up until the mappings.Add(identifier, error.Message); call, at which point the debugger stops entirely and no further execution occurs.



The strange thing here is that execution just stops, no exceptions or errors are thrown. This method is part of a larger ASP.NET project, and this method is used within a controller. When the execution halts it causes my end-point to return 404. Not sure if that is relevant or not.










share|improve this question














This is really puzzling me as I can't figure out any apparent reason for execution of my method to come to a sudden halt.



The method I have below is relatively simple, all I am doing is iterating through a collection of objects and adding some data to a new Dictionary based on the current data.



public Dictionary<string, string> MapValidationErrorToIdentifiers(List<ErrorField> errors)

var mappings = new Dictionary<string, string>();

foreach (var error in errors)

string identifier;
if (error.CollectionIndex == "")

identifier = error.Section + "-" + error.FieldName.Replace(" ", "-");

else

identifier = error.Section + "-" + (error.CollectionIndex + 1) + "-" + error.FieldName.Replace(" ", "-");

identifier = identifier.ToLower();
mappings.Add(identifier, error.Message);


return mappings;



The input object List<ErrorField>, is comprised of ErrorField objects, which are simple DTO objects.



public class ErrorField

public string FieldName get; set;
public string Section get; set;
public string CollectionIndex get; set;
public string Message get; set;



During testing of this method in one instance the errors input object contained 12 ErrorField objects, the foreach completed one iteration successfully, and a key-value pair was added to the dictionary. Then on the second iteration the method worked up until the mappings.Add(identifier, error.Message); call, at which point the debugger stops entirely and no further execution occurs.



The strange thing here is that execution just stops, no exceptions or errors are thrown. This method is part of a larger ASP.NET project, and this method is used within a controller. When the execution halts it causes my end-point to return 404. Not sure if that is relevant or not.







c# asp.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 14:06









Jake12342134Jake12342134

42812 bronze badges




42812 bronze badges















  • Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

    – CodeCaster
    Mar 27 at 14:22











  • When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

    – Treeline
    Mar 27 at 14:27











  • @CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

    – Jake12342134
    Mar 27 at 16:26

















  • Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

    – CodeCaster
    Mar 27 at 14:22











  • When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

    – Treeline
    Mar 27 at 14:27











  • @CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

    – Jake12342134
    Mar 27 at 16:26
















Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

– CodeCaster
Mar 27 at 14:22





Add() probably throws because the same key is already present, with the exception bring caught by code higher up. Enable first-chance exceptions during debugging to catch it.

– CodeCaster
Mar 27 at 14:22













When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

– Treeline
Mar 27 at 14:27





When you say execution stops, do you mean the program shuts down, or that it is hanging, not getting anywhere?

– Treeline
Mar 27 at 14:27













@CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

– Jake12342134
Mar 27 at 16:26





@CodeCaster This is exactly what it was. I enabled all exceptions and the exception appeared. Thanks!

– Jake12342134
Mar 27 at 16:26












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379224%2fexecution-seemingly-halts-for-no-reason-when-using-dictionary-add-within-a-forea%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379224%2fexecution-seemingly-halts-for-no-reason-when-using-dictionary-add-within-a-forea%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript