Code 'ghosts' in C# - c#

The problem I have run into twice now is that my program seems to be running code that no longer exists. I figure that some old version is stuck some how but have no idea how to get the compiler to run the updated code I've written.
The way I have spotted the problem is by observing that bit maps I've loaded keep getting drawn even after I've removed instructions to do so. The problem persists even after removing every reference to the image in question, content load lines included.
The first time this happened restarting the compiler didn't fix the problem but restarting the computer did. Now the problem has persisted after a full shutdown.
I m using ms C# 2008 express edition if that has any bearing.

My first thought would be that the build is failing and that Visual Studio is running the old version. I don't have VS 2008, but in VS 2010 the option to change this option is in Tools->Options->Projects and Solutions->Build and Run.

You have to figure out where the mismatch is coming from.
What happens when you run the .exe from outside VS? What about from inside VS? Can you verify that after a build, the binary you're executing has an updated timestamp? Is the stale code in a .dll where the new version isn't getting pulled in?

In my experience this happens when configuration profile is changed from debug. For instance if I am running the debug profile, it works. Then I change to the QA profile and make changes and then build the new assemblies. The assemblies are built to a directory called "QA" however, when I debug through visual studio it runs the code from the debug profile. I can remove references, recompile the code, visual studio will still run from the debug profile. It appears that none of the changes I made are in the code. When in reality I'm inadvertently running a old build.

Related

Visual Studio 2017 outputting older build versions in bin/debug folder

When I build a C# program (this has been going on for several different solutions/projects I have been working on) in Visual Studio 2017, the new, updated code will build and run in debug mode (and run correctly).
However, the application that Visual Studio has been outputting when I build/debug them has been remaining with the original, first version of code that I saved. When I choose the options to rebuild, it will update the time stamp on the application and .pdb files, but the application will perform the way it did in earlier code versions, not the most recent code version that was running problem when I ran debug mode immediately after pressing Ctrl + F5.
These are C# Console Apps with the .NET Framework 4.6.1, if that makes any difference. I checked the output folder, and it is indeed the desired folder and the one I have been looking in... so why is the time stamp updating on the application (.exe file) that it outputs, but not the code itself? What am I missing?
When I run into strange things like this in Visual Studio, the first thing that usually works is to clean the project and rebuild. If that doesn't work, I'll close Visual Studio, re-launch, then clean and rebuild again. If that doesn't work, I would start looking into any extensions you have installed that might be getting in the way of your build process.
Further, you can look into logging the extensions activity to help troubleshoot if there are issue there. See the following article:
https://blogs.msdn.microsoft.com/visualstudio/2010/02/24/troubleshooting-extensions-with-the-activity-log/
You may have already tried this, but since it wasn't mentioned I thought I'd provide it for others in a similar situation.
Two possible reasons:
(1) Your project was not recompiled during debugging. Please enable Edit and Continue under TOOLS->Options->Debugging.
(2) Visual Studio has a concept of incremental build. If you have a solution with two or much more projects and if you change source code in only one of the two projects, the "Build" command will compile only the modified project. But the "Rebuild" command, on the other hand, it will recompile all projects in this solution.

Release builds hang/crash, regardless of code

For some reason I just started having an issue with my release builds.
I'm able to run any of my projects without issue from the debug builds, I can also run my release builds as long as I attach a debugger, but when I try to run the release builds on their own they either hang infinitely (The UI crashes, but I'm unable to stop the process with task manager), or they load up EXTREMELY slowly (I've only ever had them eventually load twice, and that was on a separate machine from my main PC).
I know I don't have any viruses or any other system issues (I take very good care of keeping my system extremely clean), and I've tried running the programs with AV disabled.
Nothing I do seems to make a difference, and the fact that debug builds of my projects perform exactly as expected leads me to believe somehow I've altered a setting in VS regarding how it builds releases or something similar.
Could this be the case? If so, how should I go about fixing it?
If you need any more information please let me know.
EDIT: Something else I've just noticed about this issue is, the only time I'm able to run any of the executables I've built is if they are in the bin\debug\ folder of my project. That includes copying the "release" build of my project into the debug folder. It then runs just fine. I've also tried building an installer for my project, and it also will only run while in the debug folder, and nowhere else on my system. Doesn't seem to matter whether it's a release or debug build, as long as it's in that folder.
I ended up doing a complete uninstall of Visual Studio Community 2015 and all of the runtimes/etc. that were installed on the same date as VS, and reinstalled the program.
I then deleted all of the debug/release builds for my project, cleaned the solution and rebuilt them.
So far everything seems to be working okay now.
I'm not sure what the issue was, but a fresh install seemed to fix it.

Visual Studio 2013, changes not showing in debug

Have recently upgraded to Visual Studio 2013 Pro and am having some teething problems.
Primarily if I change any HTML or CSS in either a .aspx page for Web Forms or .cshtml for MVC, the changes aren't always reflected on the page I'm working on when I debug it and don't appear not matter how times I refresh or clear my cache.
Am using web essentials, which should put the changes straight on the page with have to refresh the page but this doesn't seem to be working either.
Also occasionally, but not always, if I stop debugging, change the code behind then run the project again it says it's running from a different version of the code than the one being debugged and I have to stop it, rebuild and then debug.
Have never had these problems on previous version of Visual Studio.
Any suggestions?
Go to Tools-Options
Under Projects and solution -> Build and Run select "Always build" under "On Run, when projects are out of date"
I had the same issue today. I already had that setting on (Always Build). Cleaning & rebuilding the solution didn't do the trick. I looked under C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ and I found a folder named root with a lot of temporary hexa-numeric named folders. Only one folder had today's date. I closed all VS 2013 windows and removed that folder. After I restarted VS 2013 I simply run the project and my changes are now back.
I just spent the past hour trying every answer and none of them worked. I simply cleared the cache on the browser I was using to debug (google chrome) and it updated my changes. This question had the correct answer:
visual studio not updating html / javascript to server / browser
I was experiencing old code in the debugger with a console application calling a DLL. I believe it was occurring because the previous version of the DLL was installed in the Global Assembly Cache (GAC), and the Visual Studio debugger was calling the DLL in the GAC (Which had the old code) instead of the current version. I uninstalled the DLL from the GAC and the problem was resolved.
Uninstall an assembly from the GAC (MSDN)
I had this issue and tried all the Build config changes etc without success. I'm running VS2015 in a Parallels VM and saving the project on a drive on the Mac. It appears that there is some odd/tiny difference between the Mac time stamps and the Win10 clock.
Setting the Win10 clock back 5 seconds resolved the issue. Bizarre but saved my sanity...
for my case, I tried all the before mentioned answers but nothing worked. and then I went to the system logs and found a hint about failure in loading IIsexpress for the running application. I changed the port that the application used and voila! everything is back to normal. thought this might help someone
I had a similar issue and found the solution by checking the path of the virtualDirectory for your sites that are found within your applicationhost.config file.
Typically located here:
C:\Users{your user name}\Documents\IISExpress\config
You want to make sure the physical path for both locations are the same since sometimes they get wonky when working on various branches/projects etc.
it's not a bug at all, and has nothing to do with the above answers.
Go to solution explorer and click on --> sync with active document. as shown bellow:

Visual Studio 2012 csc.exe Error. Executable not valid for OS

I am getting the following error when trying to compile and test any type of project in Visual Studio 2012 Professional.
Error 1 The specified task executable "Csc.exe" could not be run. The
specified executable is not a valid application for this OS platform.
After testing multiple suggestions online nothing has fixed the problem. Anyone know what is causing this? Is there a new version of Csc.exe I need to get a hold of? I know this is the compiler just not sure what I need to do to fix the problem.
I had this exact problem today on my Win7 Machine. As Hans suggests, 'Navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319 and type "csc".'
The file may still exist but if you can open it with notepad, it will probably show just plain text of some errors. This is the indication that your compiler has been destroyed. At my office we have come up with a theory that a Windows update may be causing this because only a few machines have been affected, but I haven't read much online about it until now.
We fixed this by copying someone else's csc.exe into the C:\Windows\Microsoft.NET\Framework\v4.0.30319 directory and recompiling. Be sure to set the options on the file to read-only so this won't happen again. Good Luck!
The problems associated with csc.exe in Visual Studio 2012 can mostly be solved by repairing Visual Studio.
You need to repair Visual Studio. Go to Control Panel -> Programs. Then select your version of Visual Studio you are using and press "Change"(or right click it and press "Change"). When the setup appears, click "Repair".
I am on Visual Studio 2017 but this is the first google result that pops up for "csc.exe not found"
When I got this error I had to restart Visual Studio, being sure to select 'Run As Administrator'. Everything worked after that
I've faced this problem while i am trying to move Asp.Net Mvc Project from one computer to another ; error message was : The specified task executable location "c:\users\mypcname\documents\visual studio 2015\Projects\TestMVC\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\csc.exe" is invalid.
I solved this by
Creating new Mvc Project ;
going to that folder \Microsoft.Net.Compilers.1.0.0\build..\tools
and Copied the csc.exe file to my Projets >> \Microsoft.Net.Compilers.1.0.0\build..\tools\
i think when i was copying the project from the original Computer i left that csc.exe file in the specified folder.
Hope this will help someone.
Check your solution properties (right-click on Solution and select 'Properties') and make sure that the 'platform' field (Configuration Properties) is set correctly.
I think this problem is caused due to improper PC clean up. I was running Quick Heal PCTuner 3.0 software on a 64-bit windows 7 machine but suddenly due to loss of power my machine was shut down then when i opened it again I was getting this problem in VS 2013. Even TortoiseSVN checkout was not working and throwing internal error and something like corrupted disk also was shown when trying to delete some files on the harddisk.
I ran the PC Tuner again doing the Disk, Registry and traces clean up and it got fixed. maybe this problem may occur due to other cases also but is mostly related to the system's files In my case this is the fix
Regards.
in my case helped (I had .net framework 4.5.1 and vs c# 2010 express):
download the newest .net framework and run repair
On Visual Studio 2013, the same problem solved by doing this for me:
Right click the solution and open Configuration Manager. For the project(you may see at least one there), I've changed the Platform from Any CPU to x86 for the project that may causing the problem.
I've tried to delete and move csc.exe file but it doesn't do anything.
Then simply I upgrade .net version and than downgrade (returned to its original state) and it works.
I solved my problem by copying the whole folder containing my visual studio solution
From C:\Users\me\Google Drive...
To: C:\Users\me\OneDrive...

WPF DotNET Application will run in debug mode, but .EXE will not run

I wrote a WPF application in C# using VS 2010. The application will run fine in debug mode using Visual Studio, but when I go to run the .EXE from the bin\release folder, nothing happens. I do not get any error messages from windows and there are no errors or warnings in VS. I have tried to build, rebuild and clean the solution (in every possible order) with no luck. My solution contains 2 projects, both of which use .NET 4.0 framework, and I have .NET 4.0 installed on my PC. I have tried on both XP and Win7 and still nothing.
I also just noticed that the output from Debug when I run the application in debug mode says: "Cannot find or open the PDB file" after each .Dll it loads.
I am compiling to the Release folder every time, but i did try changing it to the debug folder and clean/rebuild just to see if that would make a difference, and it didnt, so I changed it back, tried it again, and still nothing.
Any Ideas?
Here are a couple of ideas that come to mind
If you are on a x64 machine, try changing the application from being AnyCPU to x86. This the mode that applications default to in debug mode and it's possible an issue running in x64 is causing a problem in release builds
Possible the Release binaries are out of date. Delete the binaries from the Release folder, rebuild and run the newly generated runs
Run the release build under the debugger in Visual Studio and see if it till crashes
I was experiencing the above issue too, however none of the other solutions worked for me.
My Application logs in Event Viewer listed event ids 1018 and 1022. This appeared to be bizarrely related to an ASP.NET 2.0 dll (bizarre; as this was a blank WPF project only). The logs contained messages like this:
Windows cannot open the 64-bit extensible counter DLL
ASP.NET_64_2.0.50727 in a 32-bit environment
In the end it turned out to be resolved when I disabled my anti-virus. I had read that this resolution worked for someone with McAfee; and it also worked for my environment, which has Avast.
I assume you tried on a machine that doesn't have visual studio installed, and also none of the components you are using for development.
You have only one option: start the application with a debugger on the machine that causes problems and check for exceptions there. (use WinDBG for example - it's light and easy).
This looks like a problem with missing dependencies, but might be something else also.
The Debugging Labs should give you enough information on how to use windbg to find your problem:
.NET Debugging labs
Also use this:
WinDBG Cheat Sheet
(JaredPar) answer looks right (x64), but if not try right clicking on the EXE and running in admin mode for win 7.
I had a very similar issue.
Check out this setting on your App Pool entry:
Go to Advanced Settings.
Change 'Enable 32-bit Applications' to 'TRUE'.
This worked for me!
I'm going to go with a wild guess that:
Either you have some odd corruption in your .NET Framework installation
There is some debug/release-specific code using #if DEBUG or the such that is substantially different to cause issues.
You have not compiled recently into Release yet (Try changing it to Release before compiling your latest code and make sure you get no errors).
Those are the only things I can think of off the top of my head.
I had run into a similar issue, I was missing a custom folder in the release mode I was referencing in the constructor. Adding the folder to the release fixed the problem.

Categories