Advertisements

Archive

Posts Tagged ‘ASP.NET’

Modify Collection while Iterating C#

May 10, 2017 1 comment

The general rule is that you can’t modify a collection/array/list while iterating over it.

If you are trying to modify loop while iterating you will get following error message

List strList = new List();

strList.Add(“1”);
strList.Add(“2”);
strList.Add(“3”);
strList.Add(“4”);

foreach(string str in strList)
{
strList.Add(“test”);
}

Error:

System.InvalidOperationException: Collection was modified; 
enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Rextester.Program.Main(String[] args)

Here is the simple solution

int listLength = strList.Count();

for(int i=0; i<listLength; i++)
{

//Add New Element
if(i == 0)//Some codition when you want to add new element to list/array
{
listLength++;
strList.Add(“5”);
}

Console.WriteLine(strList[i]);
}

Hope it helps !

Advertisements

Unable to launch the ASP.NET Development server because port ‘1900’ is in use


The Problem

You are coding away, Visual Studio locks up for one of it’s many reasons, and reopen your project and run it again. You then get the “Unable to launch the visual studio development server because port 9452 is in use” error

The Cause

When Visual Studio crashed, the Web Server did not, so basically it thinks you are trying to run two instances at the same time, which is not allowed.

The Solution

Open up the process manager, go to the Processes tab, and select “WebDev.WebServer40.exe” and click “End Process”. Then try running your project again. Visual Studio will now start the project fresh and the problem should go away.

1

Or try this

2jpg

 

Hope it helps !

Opening project in Visual Studio fails due to nuget.targets not found error

January 22, 2016 Leave a comment

Problem:
I try to open project in Visual Studio and get all these nuget errors:

The imported project "C:\Twitterizer\.nuget\nuget.targets" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file 
exists on disk.

Solution:
Follow the following steps to resolve above error
  1. Install Nuget.
  2. Right click on the solution and select “Enable NuGet Package Restore”.
  3. Click Ok on the warning.
  4. Close and re-open the solution.
Hope this help!

AngularJS Form Validation – Disable Submit / Confirm Password Custom Directive

January 21, 2016 Leave a comment

Bootstrap and datepicker

November 17, 2015 Leave a comment

How to Access Parent Page (.aspx) control (IDs) from its child User Control (.ascx)

November 5, 2015 Leave a comment

Write below line of code in control to find relevant parent page (aspx page)’s control

Code for VB.NET

Dim MainContent As ContentPlaceHolder = Me.Page.Master.FindControl(“MainContent”)

Dim btnPrint As Button = MainContent.FindControl(“btnPrint”)

 

Hope this help !