Visual Studio 2010 SP1 is locking and preventing itself from building the project target assembly - debugging

I have a project, which contains various classes and user controls. Every once in a while, often on the second build attempt, Visual studio locks the project's target assembly and the build fails with the following error:
Unable to copy file "obj\x86\Debug\MyProject.dll" to "bin\x86\Debug\MyProject.dll". The process cannot access the file 'bin\x86\Debug\MyProject.dll' because it is being used by another process.
This same issue was reported here: VisualStudio2010 Debugging - The process cannot access the file ... because it is being used by another process. I tried a few of the presented answers, but none of them resolved the matter for me.
Any suggestions?

I read somewhere it's a known issue and they're working on a hotfix - knowing Microsoft it should come out about the time Windows 9 does.
The current only real fix is to uninstall SP1, but since I can't be bothered doing that I just delete all the project files in the Debug folder, but you have to do this every time it throws the error. You can't use a program or batch file to do this since for some reason it completely locks the file and you have to wait ~5mins for the system to unlock and delete it.

Related

Error when rebuild the setup project in c#

Im getting below error when im going to rebuild my setup project in visual studio 2015.Please advice to resolve this:
The message means that the install of Visual Studio 2010 Shell (Integrated) is broken, so Windows is attempting to repair it. Also, it looks like it was installed from the internet, which resulted in the setup being performed from a temp folder that has since been deleted. It is always better to download the setup (such as the MSI file) and save it somewhere. It is also possible that the C:\Windows\installer folder has been damaged or has had files deleted because normally the repair would be performed from there, which might have been happening for a long time but you wouldn't have noticed until the cached MSI file was removed from /windows/installer.
The fix is to get hold of the exact same MSI file that was used to install VS 2010 Shell MSI file and save it somewhere, and browse to it when this happens again.
The cause might be a conflict between VS 2010 and VS 2015, or some removed or changed shared files. The application event log will have an MsiInstaller entry that says what is missing.

Visual Studio 2010 - Cannot Register Assembly

I am running Visual Studio 2010 on a Windows 7 VM and trying to build a fairly large solution. When I try to do so, I get the error:
Cannot register assembly "C:\Development\ProjectName\Source\bin\Debug\AssemblyName.dll" - access denied. Please make sure you're running the application as administrator. Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I have taken the following steps:
Confirmed that I am in fact running Visual Studio 2010 as administrator.
Restarted the VM.
Confirmed that the assembly does exist exactly where Visual Studio is looking for it.
Confirmed that administrator has full control over the relevant file.
Cleaned and rebuilt the project (multiple times).
I have also found that building the project which creates AssemblyName.dll, manually registering it with RegAsm, and then building the project which requires AssemblyName.dll does not result in an error, but this is not a desirable workaround as it requires manual control. Can anyone give me some advice on how to solve this problem?
Many thanks.
This particular issue happens when you are building an assembly project which has the 'Register for COM interop' checked under the Compile tab of the project properties. As Stephane said, you must right click -> Run as Administrator in order for it to register automatically.
If you already have the compiled assembly from a different machine, you can alternatively register it manually and reference the compiled assembly with the project to by-pass the issue.
When you ran VS2010, did you right-click and select "Run as administrator"? If not, it actually runs as a lower priviledged user. Once I selected "Run as administrator", this problem went away.
I also ran into this error even though I was running VS 2015 as administrator.
In my case I found that manually cleaning up (ie deleting) bin\Debug\*.* for the project resolved the issue. Apparently some kind of file permissions or something was preventing the operation, and the error message may have been incorrect.
I'm not sure what was causing the file 'conflict' in the first place.
Similar to what UuDdLrLrSs said, when I tried to clear the bin folder, Windows gave an error on file access. Apparently another process was using the file - in my case, Microsoft Access.
After closing the associated program that had a file handle, the project built fine. (Although I'm still a little confused as to why it had a file handle on debug assemblies...)

Visual Studio hangs constantly during build

Probably between 25 and 50% of the times I build my solution, I see this:
"The operation you requested is taking longer than expected to complete. This dialog will close when the action completes."
I hate this window in ways I can't describe. It never resolves, the Cancel button is never enabled, and the only way to remedy it is to kill the devenv process and load up my entire solution again, knowing full well that I've fixed nothing and I'm equally liable to see the same thing when I attempt my build.
My solution is about 60 projects in total, which are mostly C# class libraries, with a few each of web applications, web services, and console applications. However, the problem persists even when building one slice of the codebase with the majority (50) of the projects unloaded.
My problem is that the output windows doesn't tell me anything at the point at which it freezes, and I don't know how else to determine the cause of this lockup. If I were to guess, I would assume that it's a deadlock in the filesystem or something, but I don't know how to go about proving this--much less how to prevent it.
What can I do to diagnose and eliminate this from my solution so that I never see it again? In general, how can I diagnose problems that occur during a build?
Had a similar issue, VS would hang for 45 or so seconds then build for 4 seconds and complete. The 45 seconds of hang would not produce any output to GUI and VS would hang.
Using ProcMon I could see 3 million+ file operations on the /packages/ folder via devenv.exe when I would build this project (and would continue for some time after)!! The first steps of the build you can see that it was checking EVERY PACKAGE to see if it needed to do a package restore (it did not).
Since I tend to blame NuGet for everything, I disabled NuGet Package Restore "allow NuGet to download missing packages" checkbox under Visual Studio -> Options -> Nuget Package Manager -> General. To my delight, the build was very fast. 5 seconds total!
Turns out that we had enable package restore on build enabled (I think this is on by default now in VS) AND we also had the packages checked into source control. It seems this causes TFS to thrash in some way... Checking for restoring packages must trigger TFS to do some source control operation checks.
FYI this was VS2013 UPDATE 4 - Nuget version: 2.8.50926.663, on a sln with NumberOfProjects = 38, but I could recreate this hang just building a single csproj with 2 dependencies.
Update:
Localhost "Rebuild All" on Sln with SccNumberOfProjects = 53 was taking 7:05 with 2 minutes of visual studio frozen / unresponsive
down to 4:14 on a 2 core i5 with no freezing
down to 2:44 on a 4 core i7
Also: This was on a machine with various file watcher security tools, likely not adding any speed to this whole process... and possibly to blame.
Update in 2021:
If you are looking for a paradigm shift, the new SDK style csproj format (see migration tool) + nuget PackageReference makes updates almost instant (< 20 SECONDS for same projects in scenarios above) - highly recommend you upgrade any legacy projects.
** Known incompatibility - website package references do not support static file references via nuget ( checkout LibMan)
I have seen this happen on large projects when MSBuild is running with the diagnostic switch turned on. In Visual Studio, go to Tools / Options / Projects & Solutions / Build And Run, then check the MSBuild project build output verbosity value. If its not set to Minimal, try setting to minimal and see if your builds are able to complete.
I did not try any of the above solution as by the time I tried my approach - all was well again.
My steps are as following:
Close VS
Delete the .vs folder
Open my solution
Clean Solution OK
Build Solution OK
Optional Rebuild OK
In my case setting "maximum number of parallel project builds" to 1 kinda helped (i.e. building a project from clean state causes 1 min freeze followed by normal build and every subsequent build works fine).
Aforementioned setting can be set in Tool -> Options -> Projects and Solutions -> Build and Run.
Seems like running Visual Studio as Administrator solved the problem for me! (For always running a program as Administrator see How to Run Visual Studio as Administrator by default)
I've found Visual Studio hanging a lot on building larger projects. Turns out it was ReSharper. After I turned it off: Tools -> Options -> ReSharper -> Suspend Now, everything built fine no issues (even on very large solutions, 100+ projects)
There was a suggestion on Microsoft Connect that Modelling project was responsible for the freezes. I removed a Modelling project from our solution and have experienced no freeze since then (about a week).
For me it was something to do with npm package install that ran automatically. I went to Tools > Options > Project and Solutions > External Web Tools and unchecked all external tools and restarted VS. After that, I was able to build it again. I know I need them to be checked but I need to figure out what's triggering them and what's wrong with this solution file.
VS2019 exhibits this issue as well for me, in my case, the problem was because of dependencies stored on a network share. I have a hunch that Windows Defender Antivirus was scanning a lot of extra stuff that was in the network share, which is only accessible when connected to a fairly slow VPN.
For me the issue was witch an extension that automatically runs T4 templates on build (AutoT4). Disabling it when working with solutions with EF fixed the issue.
I moved my VS 2008 development platform from Windows 7 to Windows 10 and encountered a situation where Visual Studio would hang up every time I tried to build a large project. I had to build the project, then use the Task Manager to kill VS and then restart. Needless to say, this made debugging really difficult! Anyhow, the problem was that in moving to Win 10, VS was no longer running as administrator (and perhaps Win 10 is more particular about privileges). Changing the properties so that the program ran as administrator resolved the problem. (IngoB -- I don't have enough status to comment on your post, but thanks for pointing this out!)
Just try below command with admin mode. Before running this command make sure to close all VS instance.
devenv /resetuserdata
Note: devenv is located at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
In addition to the felickz's answer which solves (or almost solves) this problem for builds:
Except the problem during a build I also had problem with the Package Management Console. It took about a minute to wait for it. Using the procmon I found that the NuGet repository folder was parsed each time this window is opened (very smart, Microsoft!). There were about 1000 packages in this folder. After removing everything from the above folder the performance problem diapered.
Note that my answer relates to the VS 2015 (and may be below). I didn't tested, but suspect in VS 2017 it should be ok.
Visual Studio 2017
Removing Anaconda3 from the installation fixed it. In procmon I saw hundreds of thousands of calls looking for files in the Anaconda3 folder from hundreds of instances of powershell spawned by msbuild.
I had this problem because of an issue restoring nuget packages. There was a duplicate entry in the packages.config file. Rather than report it as an error, the build would just hang forever.
I didn't discover the problem until I tried to restore the nuget package through the "Manage Nuget Packages..." option in the menu. After removing the duplicate, the build completes properly.

Notorious Visual Studio Error C1902, VS configuration

I am getting the notorious "Error C1902: Program database manager mismatch; please check your installation" in my VC++ builds in Visual Studio 2010. My VS will not even build hello world, there is no pdb file even in existence in the folder.
Steps I have tried:
cleaning and rebuilding (3 different projects including hello world, about 15 times)
removing every single instance of Visual Studio before version 2010 from the computer including all redistributables. There is no copy of mspdb*.dll on my computer anywhere except the latest version (100) in my 2010 directory.
Reinstalling 2010. I completely reinstalled VS 2010. No effect.
Rebooting my computer. I have spent the afternoon deleting anything that might be remotely related to this bug and rebooting over and over again.
I solved the problem by finding an obscure post to a similar thread created a couple of years ago on a different forum. Here is the solution:
Copy the file mspdbsrv.exe from the VisualStudio/Common7/IDE directory to the /VC/bin directory.
cyglas-config solved the problem on my build system. Is seems that Vs2010+ needs this but vs2008 didnt.
I have seen this caused by two projects sharing an intermediate directory.
Make your your VS2010 is running under administrator and have the right permission.
Our IT deployed a tool for blocking access to several "ports", it turned out all my VC project cannot build in VS2010. He then re-deployed the tool with "allow elevated program access blocked 'ports'" checked and everything is back to normal.
Verify local user account if ran under automation is not locked. this turned out to be a resolution for issue I had seen with "fatal error C1902: Program database manager mismatch; please check your installation" message.
I had the same error, and the problem was that the "mspdbcore.dll" file was deleted from my \Microsoft Visual Studio 12.0\Common7\IDE\ folder. This post helped me solving my issue.
PS:The deletion was made by a "duplicate files cleaner" utility.

vcxproj file won't load into solution

We've just recently switched to VS 2010 and i had a solution that was working fine. This moring when i try to load the solution i get the error:
"An item with the same key has already been added."
This occurs when it is trying to load one of our main projects and it is not loaded.
I assumed the problem was with my solution so i created a brand new empty solution and tried to load the same vcxproj and got exactly the same error.
When i revert the project file to a previous version it works, so apparently it's something in the vcxproj file. However it also appears that i'm the only one in the office that is affected. So some combination of the vcxproj file and my computer seems to be the issue.
Has anyone seen anything like this before? Any ideas on a solution?
Thanks
Still not sure what caused the issue however deleting all temporary files:
<proj>.vcxproj.user
<proj>.vcxproj.filters
<proj>.vcproj.<domainname???>.<username>.user
<proj>.suo
has fixed the problem.
I suspect it was just
<proj>.vcxproj.user
<proj>.vcxproj.filters
or both that actually fixed it but I did delete all 4 so it could have been any of them.
The change to the vcxproj file that casued the break was renaming some files and adding some files, so my guess is that one of the generated files had a stale reference that was blocking the load.
If you figure out how to get the message again, maybe you could open a bug at https://connect.microsoft.com/ and attach the zipped up .vcxproj and *.sln files so we can fix it.
Dan [msbuild]
i had same probleb do the following thing in windows explorer
Based on my understanding, you will get the same error even when you create every simple Visual C++ windows phone project from VS2012. In this case, I doubt that the issue is related to your VS.
And according to Konrad’s reply in this thread with similar issues: http://social.msdn.microsoft.com/Forums/en-US/cba01040-067e-4ac3-ba4c-a8a14ba3c45d/unable-to-read-the-project-file, I feel that you can check if this file: C:\Program Files(x86)\MSBuild\Microsoft\WindowsPhone\v7.0\Microsoft.Cpp.Windows Phone.7.0.targets is on your system. If it is not there, I doubt that your VS installation is wrong.
If you are not using VS Express, you could locate to the IDE folder then run these commands to check if it can help:
Please open Windows Explorer, and navigate to <Visual Studio Installation Path>\Common7\IDE
Devenv.exe /SafeMode: Launches the IDE in safe mode loading minimal windows.
Devenv.exe /ResetSettings: Restores the IDE's default settings, optionally resets to the specified VSSettings file.
Devenv.exe /ResetAddin: Removes commands and command UI associated with the specified Add-in.
Devenv.exe /ResetSkipPkgs: Clears all SkipLoading tags added to VSPackages.
If no help, I suggest you try repairing your VS or uninstall it and then reinstall it.

Resources