I have a small application, it launches properly without debugger and all the features work except one which uses IronOcr (package from NuGet package manager). When I try to use this feature the program just closes.
When I launch this application from within visual studio, everything works fine. No errors and all features work. I get the same result if I run it and attach the debugger to it afterwards. However if I run the exe by launching the exe /bin/release and do not attach the debugger it crashes when I try to use the feature involving IronOcr.
I tested this on a virtual machine, same results with/without debugger. I then tested it on a different computer (fresh install of windows only having VS installed) it gave me this error if debugger is attached:
System.IO.FileNotFoundException: 'Could not load file or assembly 'IronOcr, Version=2021.2.1.0, >Culture=neutral, PublicKeyToken=c2cbcea5ea3f6d8d' or one of its dependencies. The system cannot >find the file specified
I've spent the last few days looking up a reason for this but I have not found one so far that fixes the issue.
What is confusing me the most is:
I assume the error that causes the program to close is the same error that causes it to give this error on the different PC. When I run it through VS it has no issues (it finds the file?) but running it from the exe it cannot find the file. I'm not moving the exe, just running it where it is in the bin/release.
I'm hoping this program will be able to run as a standalone exe.
I am still relatively new to c# and VS, the error may be glaringly obvious, or I may be using the wrong words causing me to not find a solution.
probably a bit too late, but your problem certainly comes from the fact you're using the free licence of IronOCR. It seems that this one only works when the debugger is attached.
If you catch the exception, you get that message:
IronSoftware.Licenses.Exceptions.LicensingException: IronOcr must be
licensed for deployment outside of the Visual Studio development
environment. https://ironpdf.com/licensing
In my opinion this is too restrictive for proper evaluation, so I gave up trying to use it.
Make sure IronOcr.dll is exist at same directory as your executable file.
Try to execute your application from Bin/Debug and see if it runs ok or not.
Check to see if IronOcr.dll exist in Bin/Debug but does not exist in Bin/Release. if so then copy it from Bin/Debug to Bin/Release.
Related
When I build or rebuild my solution I get the error:
Error CS2012 Cannot open 'C:\Users\myUserName\Documents\Visual Studio 2017\Projects\mySolutionFolder\myProjectFolder\obj\Debug\myExecutable.exe' for writing -- 'Access to the path 'C:\Users\myUserName\Documents\Visual Studio 2017\Projects\mySolutionFolder\myProjectFolder\obj\Debug\myExecutable.exe' is denied.'
However, when I build the project, it compiles fine. Once I build the project then a solution build doesn't throw any errors. I am running visual Studio 2017.
What I've tried (without success):
There is a second project in the solution, but I've unloaded it and it still errors.
I deleted the solution file and had visual studio create a new one.
Additional Info:
The error is somewhat random. Usually it errors out, but sometimes not. The odds of an error are reduced the longer I wait between a "Clean" and a rebuild. I have the same problem even when running in Administrator mode. I'm beginning to think it's a hard drive issue.
The application is still running.
\Debug\myExecutable.exe' is denied.' is telling you that you cant replace that because its currently open.
Open task manager and make sure that you end that process, and it should work fine after that.
This is usually what happens to me when I get that error.
Hope this helps
There is a file handle still open for myExecutable.exe. Probably because it is still running (check task manager/process explorer).
If that is not the case, you can try find out which process has has a handle open to said file:
get Process Explorer
Press Ctrl-F to find handle
Enter myExecutable.exe and look for processes that have a handle to the file.
I was working on a WPF application in Visual Studio 2015 and all went well until unexpectedly the build dropped me the CS2012 error inform me that it cannot access/update the executable in the /Debug directory.
I tried the following and it didn't work:
Restart
Close VS and open the application again
Build->Clean
I couldn't find any solution in the web so I tried:
1. to move the whole project directory to another location.
2. creating a new WPF project and assembling it file by file with copy/pastes.
The weird thing was that in both cases the application worked in the new location. I continued the experimentation (in the original directory) and i tried to build a "Hello World" Console application in the same directory. The result was that the trivial console application didn't work and produced the same problem as the WPF application (CS2012 error).
Since I haven't noticed any activity of another program (i.e., antivirus) trying to quarantine (or changing the file/folder permissions of) this folder, I assume that this has been done by VS somehow but I don't know why. Perhaps it is a bug.
Is anyone has a logical explanation about this problem? And a way to fix it?
I found that my other running solution was referencing the same < executable path>.
Just make sure that no other process is using the referenced folder/file/dll
Try to close all processes, move the project to a different folder (on a different disk) b restart the computer and everything will work as it should. It worked for me without any problems. Hope this helps someone
I wanted to quickly test something in a .NET Core Console Application Solution and ran into this issue due to BitDefender blocking the resulting binaries.
I've named the app client which actually was the culprit. Renaming my solution fixed this.
Sometimes antivirus softwares can block copying an exe file from a folder to any path. You can manage by settings or the easiest way is to shut down live protection while you are coding and debugging.
:)
Deactivate your anti-virus for a while and try again.
This works for me.
When I run my command-line application from within Visual Studio, one command always fails with below error:
The program '[7316] MyProgram.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
When I debug the code, this happens after the last execute line. Meaning the application performs it's function correctly but then crashes. When I build the project and run the exe file in the command-line I get no error and it works fine.
The project uses a 3rd party dll which in turn AFAIK calls a C or C++ dll, eg. something not coded in .Net.
My questions: Can I ignore this error since the app works fine when built? If not, what could be the potential issue and how can I solve it?
Can I ignore this error since the app works fine when built?
I wouldn't ignore the issue. If your application fails during closing, there is possibly something wrong in destructing the objects and returning the handles to Windows (most likely the latter). This might get you in a production scenario eventually.
If not, what could be the potential issue and how can I solve it?
As said, I think releasing handles is the issue. If you use some third party DLL which is written in C++, possibly there is the issue. Try to set up some logging and see what the stack trace of the exception is. This might give you an idea where the problem is caused. Maybe this is even an issue you can report back to the vendor of the DLL.
I have set an output folder for my .dll project though the Project Properties, which I call "Output".
The problem is, from an empty Output folder, the first time I Build the project, it's fine. The second time, I get the following error:
Error 328 Unable to copy file "obj\Release\MyLibrary.dll" to
"......\Output\Release\MyLibrary.dll". The process cannot access the
file '......\Output\Release\MyLibrary.dll' because it is being used
by another process.
The "another process" is the vshost.exe from Visual Studio. Since it keeps acessing MyLibrary.dll, it can't be deleted or replaced, thus why the error. This keeps the MyLibrary.dll on the Output folder not updated. However I have other .dll projects in my solution in which this does'nt happen.
The solution I have used so far to update it is to close the VS (thus closing vshost.exe), then run a .bat file which deletes the file Output\Release\MyLibrary.dll, then open the VS again and Rebuild it's project.
I know little of what exactly vshost.exe does, so I have no idea from where to start to clear this problem from the root. I don't know why this happens to a specific .dll. I appreciate any idea that helps me investigate why this happens.
vshost.exe is the Visual Studio Hosting process. It is a custom CLR host that loads your EXE and makes debugging easier. You can turn it off, that has very few side-effects. Project + Properties, Debugging tab, untick the "Enable the Visual Studio hosting process" option.
You are more likely to find the real problem in your program now. With the most common issue that your program doesn't quit when you ask it to. You will still get a build error, you'll now see your own EXE fingered as the one that keeps a lock on the DLL. You will also see it back in the Task Manager's Process tab. Which also allows you to kill it.
It isn't that clear to me how programmers recreate this problem. Pressing Ctrl+F5 instead of F5 certainly will do this, always press F5 to immediately attach the debugger when you start the program. Using Debugger + Stop Debugging will now reliable stop the program. You can otherwise use Tools + Attach to Process to get a debugger attached again later to find out what your program is doing.
Anti-malware is a common scourge worth mentioning, they get way too excited when they see an executable file appear from nowhere. If you use Avast then just uninstall it completely, it is quite incompatible with VS.
I get latest from source control and can not build my visual studio solution. I get the following error:
Cannot copy assembly 'XYZ' to file 'C:\myfolder\bin\Debug\XYZ.dll'. The process cannot access the file because it is being used by another process.
I have rebooted the machine but nothing seems to work. please help.
Use ProcessExplorer to determine what other process is holding the DLL open - my bet is that it is Visual Studio itself. Try closing down any open form Design windows (or all code/design windows in VS.Net for that matter) and see if you still get the same problem.
You can use the handle tool to determine what process is using that file:
handle XYZ.dll
From there, you can figure out what started the process and why it's using the file.
Whenever i've seen that error, it was because the program i was trying to compile was still running. You may want to check and make sure any debug sessions are stopped (not just paused, but stopped completely), and that your program doesn't appear in the Task manager under the "Processes" tab.
Try changing the build configuration from Debug to Release and try compiling again.
let's try a simple solution. The DLL in your bin directory is likely marked as Read-Only. Visual studio doesn't check out the DLLs from the BIN directory when you check out source files. So if you keep the binaries in source safe then you need to manually check them out or manually take off the read-only flag in the directory.