cannot access because it is used from another process - vb.net

Well suddenly when I’m trying to run my project from the debugger in Visual Studio 2010 It gives me this error:
Error 40 Unable to copy file "obj\x86\Debug\AssetsManagement.exe" to "bin\Debug\AssetsManagement.exe". The process cannot access the file 'bin\Debug\AssetsManagement.exe' because it is being used by another process.
Please is there someone how knows why that happens?
I have already delete the x86\Debug subfolder and te bin\Debug subfolder but nothing happen
Especially in the second folder the only file which cannot deleted was the the .exe file Also with the same error.

Most of the time when I see this error I go look in task manager and I see a VSHost file for my project running. You can't kill it, it just comes back. It's gotten to the point now I always uncheck enable visual studio hosting on the debug tab when I start a new project.

Try commenting out AssemblyVersion in AssemblyInfo.vb and performing a build.
Assembly: AssemblyVersion("1.0.0.0")
This has worked for me.

Related

VB.net .exe cannot be run from another computer. Missing assemblies for ClosedXML

I must put this program into production today, and I can't get it to run independently.
In the program, I have included NuGet package "Imports ClosedXML.Excel" and use it to create spreadsheets. When I build my executable, and try to run it from another computer, it cannot find the ClosedXML and Documentformat.OpenXml assemblies.
I checked in References that "Copy Local" was = True for ClosedXML and Documentformat.OpenXml, but it's not working. I found another website that mentioned Global Assembly Cache, and that if the dependency is in there, it will not be included in the Build .exe.
I am running Visual Studio Professional 2017. I am in over my head on this one, so if you have answer (and I hope you do), please try to provide it in elementary terms I can understand.
Sometimes issue is solved by individually adding application files inside the following menu
Go to Publish-->Application Files
Select Show all files
Under Publish Status
Set the files you need to Include [not include(auto)]

Build error when signing with snk key

Build error is occurring since using Visual Studio 2015. When building in Visual Studio 2015 this is occurring rarely. When building in TeamCity this occurs very often.
[Error in Visual Studio 2015]
Error extracting public key from file 'CompanyName.snk': The process cannot access the file 'C:\Users\UserName\AppData\Local\Temp\tmp2FF6.tmp' because it is being used by another process. CompanyName.Project.DAL D:\Projecten\CompanyName\Repository\Source\Components\CompanyName.Project.DAL\vbc
http://i.stack.imgur.com/hKbbe.png
[Error in TeamCity]
CSC error CS7027: Error signing output with public key from file 'CompanyName.snk' -- The process cannot access the file 'C:\BuildAgents\Gamma\temp\buildTmp\tmpD91D.tmp' because it is being used by another process.
http://i.stack.imgur.com/rbgHx.png
I know it's been a while since this was asked but as I use SO for my own reference and I had this problem too I wanted to share my solution.
.snk files are for signing a project. You might need to make a new one.
Right click on your project, select properties.
Click on Signing.
Click the checkbox beside "Sign the assembly".
On the dropdown labelled "Choose a strong name key file" click new.
Fill in the dialog box as you wish noting particularly the Key file name. When you press ok, this will generate a new .snk file.
Save the project and rebuild.
This will use the new .snk in your project and will resolve the
error.
Hope this helps.
Try to clean up the temp folder that is used by the build.
I have seen different types of problems when the temp folder has lots of files.
Some of the tools are using GetTempFileName and they will get errors when temp has a lots of files
The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
This is probably an instance of this issue with Roslyn compiler. The workaround would be adding
<UseSharedCompilation>False</UseSharedCompilation>
under any <PropertyGroup> node in .csproj file.
It started for me when I moved the Resharper Cache to System Temp. When I moved it back to the Solution folder, the problem went away, and I could build again.
I just had the same problem. In Visual Studio 2015, I fixed it using the following steps:
Go to Tools > Options
From the Options dialog, select "Projects and Solutions > Build and Run"
Set the "maximum number of parallel project builds" to 1
+1 to #stukselbax for getting me on the right track
Also got help from this link
I used '/m:1' as an msbuild argument, and 'SignPublic' property to true in the csproj file.
Just had this issue today in visual Studio 2022- I was messing with the csproj file and ended up having the wrong filepath to the snk file. I fixed it by changing the filepath to be correct.
Right-click on the project -> unload (so that you can edit the csproj file)
Under <PropertyGroup> check the <AssemblyOriginatorKeyFile> tag
My code was:<SignAssembly>true</SignAssembly> <AssemblyOriginatorKeyFile>../NAMEHERE.snk</AssemblyOriginatorKeyFile> NAMEHERE was specific to my project, yours will vary. Look at your snk file. The ../ in front will vary, check the filepath of your snk file. If you caused this error by messing with your csproj file, like I did, then the correct answer is what the filepath was before you changed it. :)
Right-click on the project -> reload

MSBUILD Error MSB4025 in TeamCity build step for Visual Studio

When I run my TeamCity build with the only build step being of runner type Visual Studio (sln), I get the following error:
C:\TeamCity\buildAgent\work\4978ec6ee0ade5b4\Test\Code\Test.sln(2, 1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 2, position 1.
This is on a dedicated CI server running TeamCity Professional 8.1.1 (build 29939). There are several other successfully-running builds on this server.
The odd bit is that the same build runs successfully on TeamCity on my dev machine. I followed an answer to a similar question, and copied the specified folders across, but that didn't help.
I'm sure the project/solution file isn't invalid because in addition to the build running on my dev box, I have opened the solution in Visual Studio and built it there with no problems.
Any suggestions?
I just fixed this.
Look inside the Test.sln file for Project or EndProject tags that aren't closed. For us, the EndProject was missing and it broke on teamcity, but no issues in Visual Studio.
It seems the TeamCity error message will occur for any number of root causes. In my case the problem occurred because a line inside the GlobalSection(NestedProjects) section was referring to a project Guid which didn't relate to any project defined in the Solution file.
As with the previous post I didn't have any issues building in Visual Studio. I only got a more helpful error message that allowed me to discover what the real problem was when I built using msbuild.
See https://therightjoin.wordpress.com/2014/07/04/msb4025-the-project-file-could-not-be-loaded-data-at-the-root-level-is-invalid-error-when-building-ssdt-project-in-teamcity for another example, and where using msbuild helped identify the true problem.
In our case, it was a duplicate project reference in the solution file (caused by near simultaneous commits and an automatic merge).
In our situation the problem was specifying a ToolsVersion that was not installed on that machine. (14 which VS2015 has but VS2017 does not have by default)
In my case, after merging, in .sln file, it was a mismatch of lines under
GlobalSection(NestedProjects) = preSolution
{6B971E15-6B61-4AA8-9B93-9639C23269C3} = {9A14E7EF-3FA1-4B9A-B413-C550B3E5AC62}
{54D14F01-D576-4DE6-9404-D21AD0DC4916} = {9A14E7EF-3FA1-4B9A-B413-C550B3E5AC62}
... (was some extra entry here )
...
EndGlobalSection
section. In clear words, there were some extra lines added after merging. So, If you have merged, please compare two solution files manually. You can start with total line numbers in both files.
In another Case
We had a blank lines - so make sure any blank lines are removed!
Hope this helps some else too!
I got this same error with Jenkins. It turns out the root Jenkins folder was set to C:\Program Files (x86)\ and it didn't have write access to bin and obj directories.
Error:
error MSB4025: The project file could not be loaded. Data at the root level is invalid.
I launched cmd as Administrator and ran this:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "C:\Program Files (x86)\Jenkins\workspace\BuildBI_1\Reports\Test\ReportsTests.sln" /t:Build /p:RunOctoPack=true
And that gave me clues about not being able to write to bin and obj.
This worked for me-
You can install Build Tools for Visual Studio 2017, make sure to select C++ tools, Windows 10 SDK and MSBuild and your set.
Use MSBuild to identify the underlying problem:
$> msbuild mysolution.sln
Gave me this beauty with the correct error line number:
If msbuild cannot be accessed like that from the command line / powershell, try to find the MSBuild.exe shipped with VisualStudio, e.g. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\amd64\MSBuild.exe.
VisualStudio itself seems to be very "tolerant" against errors / inconsistencies in the solution file, so having it open in VS is no guarantee for the sln file being correct.
I fixed it by updating the solution file.
Another possible problem (and resolution): I had a stray unused solution file in my repo, pointing to who-knows-where, and the MSBUILD step in my Azure DevOps pipeline was set to **\*.sln.

VS2012 Compiler randomly tells that output file can't be written

I am compiling a bigger VB.NET project using VS2012.
Randomly, but very often after having run my project in Debug Mode, I get the error
"The output file <mypathhere> could not be written. Permission denied."
I have also tried using MSBUILD to give me more details about this error, but it didn't help.
Also, I have tried disabling the Hosting option because I thought that this might be the cause, but it wasn't.
I used ProcessExplorer to find out which process might have locked my file, but it didn't show anything.
Does anybody have any more ideas?
When I try to set the application's output folder to not-writeprotected using the Windows properties dialog, I get the "Changing attributes denied. Permission denied." error on the output file.
Thank you very much!
There are a couple of reasons why this could happen
An instance of your program is currently running hence Visual Studio can't write over the file. Next time this happens check and see if any instances of your program are running in task manager.
An anti-virus program has a lock on your file to analyze it and prevents VS from overwriting it. Try excluding your project director from analysis and see if the problem dissapears
The solution is to activate the Application Experience service in Windows. This is a known MS bug.

Include project reference in debug

I built an online login program which connects to my online MySQL db. In my application i have used the MySQL.Data file as a reference since the program needed the file to connect to the online MySQL server. Now my question; when I take my program from 'C:\Users\User\Documents\Visual Studio 2010\Projects\MYPROJECT\MYPROJECT\bin\Debug' and copy that file to a completely other computer, I get an error message saying that the MySQL.Data file is missing. I want to know how I can include the MySQL.Data file in my project compile. If you need further details I am happy to provide them.
In the Solution Explorer of your project, you have the point References, where the MySql.Data.dll should occur. Right-click it and select Properties, and in the Properties make sure that Copy Local is set to True.
Then, the MySql.Data.dll file will always be copied to your bin/Debug folder.
If you deploy your program, you have to copy that dll, too. Then everything will work on the other computer.
You can build a setup project (installer), or copy the mysql.data.dll file with your exe (basicly everything in your bin/{config} directory).