Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio running the wrong code

I have found and issue with VS 2013 where it will run the code of the latest instance of VS that has been opened. This is frustrating as I sometimes must look at differences between two versions of the same large project.

How to reproduce: (the example that I am using can be found on github: https://github.com/charles1024/VS2013-Crossover-Bug)

I have two copies of the same solution, which I will refer to as Hello1 and Hello2.

Hello1 has a line in Default.aspx that will set the text of a label (lblHelloWorld) to “Hello World”.

Hello2 has this line, but it is commented out.

Steps to reproduce (important to follow exactly):

  1. Open the solution in Hello1
  2. Start debugging Hello1
  3. Observe that in the upper left there is a label with the text “Hello World”
  4. Stop debugging Hello1
  5. Open the solution in Hello 2
  6. Start debugging Hello1 again
  7. Observe that “Hello World” no longer shows up in the upper left.

Can this be fixed by changing a setting somewhere or is it actually a bug? Are there any workarounds?

Notes:

Some people have suggested changing to port that it is running on. I tried this and it didn't make any difference. The solution ran on its original port yet still ran the code from the second instance of VS.

*Correction * I just checked it again and the port number seems to have fixed it. Apparently just saving Hello2 didn't make the port change take effect. You have to close everything and re-open.

like image 656
charlesw Avatar asked Jan 22 '26 00:01

charlesw


2 Answers

This is not a bug in Visual Studio. You have two web projects open that are both using IIS Express on the same port (15770) so whoever grabs the IIS Express virtual directory last is "winning".

Right click on the project -> properties -> Web. Change the project url to something like 15771 on one of the projects (you will be asked if you want to create the virtual dir). Now both will run side-by-side.

like image 138
Paul Abbott Avatar answered Jan 24 '26 17:01

Paul Abbott


Since you are using the same port number, you have a "last one in wins" type of scenario. You can prevent this from happening by using different port numbers in the project url. Currently you use http://localhost:15770/ as the project url. Change it to another number is one of the projects.

You can change this setting in the project properties page. Change this setting

like image 26
Lukkha Coder Avatar answered Jan 24 '26 17:01

Lukkha Coder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!