Can't seee ClickOnce error before window closes - c#

I have a ClickOnce cmd line app that is throwing an exception on initialise. I can't see details of the exception because the console window closes before I can see it.
I have tried launching (my using the shortcut from the start menu, simply dropping it on to the console window) but it launches a separate console, writes the error to that and closes!
How can I see the error?!
Thanks
Ryan

I recommend tracking down the executable in the ClickOnce cache and double-clicking on it to see if it's a ClickOnce problem or a problem in your application.
The cache is in C:\Users\username\AppData\Local\Apps\2.0\obfuscatedfolder\obfuscatedfolder and from there you'll have to look in the folders for the one with your exe in it.
If it works, then it's a bug in your app. I'd put some messageboxes or logging in your app, or put in a try-catch around the start routine and have it show the exception and prompt the user for input in order to continue.
If it doesn't work, I would install .NET 4 on the machine and enable the enhanced ClickOnce logging and then check out the log file. (Note: The app does not have to target .NET 4, it just has to be installed on the machine.) Here's an article on how to enable enhanced logging for a ClickOnce application.

Here is a little quick & dirty solution:
Use a .bat file.
In the first line launch the shortcut, the second line is just a pause.
start shortcut_name
pause
Here is good link if you're not familiar using with .bat files

Related

Starting WinForms application doesn't work

I created a WinForms application project. The simplest one. When I hit ctrl + F5 nothing happens, and Visual Studio freezes.
And sometimes I get this error:
(Unable to copy file "obj\Debug\Project1.exe" to "bin\Debug\Project1.exe". The process cannot access the file 'bin\Debug\Project1.exe' because it is being used by another process.)
But often output window is absolutely empty.
When I start it in debugging (F5) mode it works. It never happened to me before.
I checked Task Manager and it seems that the applicatin process is already started when the project is opened in VS and when I try to run the application another process is created. So, in that moment I have two identical processes. Maybe there lies the problem, but not sure. How to solve this?
Thanks to Zorgatone's answer (which is in the comments), in my case, the solution was to disable Avast antivirus.
Possibly a registry file is missing? Have you cleaned registry's recently? Try start it in Compatibility settings to one lower than your current OP should temp fix it. The task manager process not being there is because it has services that run alongside it, identify and shut the related ones.
Your system files may by corrupted. Try to run sfc https://support.microsoft.com/en-us/kb/929833
From the toolbars, open the output console and watch while the libraries are being loaded and check when the problem occures. Also paste the output log.
I have faced this problem of "being used" etc. In my case, yes, the project was already running or the exe was running. I just had to close or end the one that was running (or close Visual Studio) and start again. I found it strange too. I guess, in the debug mode, VS kinda tries to write the exe in a temporary way to run it and if there is an exe already present in the debug folder, this error is thrown.

Application is extracting itself every time when runs

I have created an application with WPF and code is used C# but it gives a problem that whenever setup is silently installed with cmd command e.g.
setup.exe /s /v/qn
it works perfectly to extract all the items containing in it after above given lines. But once setup is completed we try to run this application, it executes but shows below given image
Setup is created in installshield and it has the option not extract msi cache in local computer. Please help me to find why this problem is occuring.
That has to do with the auto-repair features of Windows Installer.
I guess you are using advertised shortcuts. Every time a user uses this special kind of shortcut to run a application, the Windows Installer performs an integrity check of it. If there are any detected problems, the installer performs an "Repair" before the launch of your application. This seems to be the case.
You can detect advertised shortcuts in the property-dialog of the start-menu. The target-field will be disabled and does not contain a path to a executable.
A possible workaround is to use regular shortcuts but this will not solve the real problem which causes the dialog to appear.
You could try to investigate further with ProcMon (https://technet.microsoft.com/en-us/library/bb896645.aspx) and see if there are any problems during the startup. Another option you have is to force logging (https://support.microsoft.com/en-us/kb/2545723) and see if there are any information that will help you finding the cause of this error.
Another entry-point for the self-repair is the creation of COM-objects which come with your installer-package.

error "unable to copy file because it is being used by another process

I use windowsform application using C# language, I have many forms, and when I want to traverse from one to another, I use this.Hide();
When I use this method, I receive the shown error,
I know that the solution is to end process using windows task manager, But the question is that Is there any way I can use travel between forms without leading to this error?
Error 9 Unable to copy file "obj\x86\Debug\WindowsFormsApplication1.exe" to "bin\Debug\WindowsFormsApplication1.exe". The process cannot access the file 'bin\Debug\WindowsFormsApplication1.exe' because it is being used by another process. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 2868
Easy going solution is to add some code in Project Properties..
Just go to Project tab and select project properties..
From there select Build Events tab.
And in Pre-build event Command line add the following code..
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
Although you Hide() your forms, they still remain as a part of the process. If you don't close every form properly, the process will remain running and you cannot recompile your project and eventually you will have to kill your process using the taskmanager.
Visual Studio tries to rewrite your executable and if the executable runs as a process, Windows will refuse to write to your .exe.
Just delete the .exe file in the bin folder: bin\Debug\WindowsFormsApplication1.exe
Don't worry, the build will create a new one.
I believe this is happen while you compiling the application or you start debugging the application.
This may be due to.
While you stop the debug in VS, the process may not be stopped.
May be you just executed the application, by double clicking it.
Might be some issues due to permission. If you are using source control, some folders may be treated as read only while downloading the project. So you need to edit that manually.
Make sure that you used Application.Exit() to exit from all the process.
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.exit.aspx
I finally how fix it. Why we can't continue debug after the first debug because the first debug exe still running. So that, after first debug, you need to go to Task Manager -> Process Tab -> [your project name exe] end the exe process.
close visual studio
in windows 7
click Shift + Ctrl + esc
in Tab processes
find process like the name of your project and end it.
I managed to fix it by deleting the suo file (hidden solution file).
Simple method is to delete the .exe file from the project directory folder and build the project again. this will create new exe file and problem will solve.

EXE not running, accidental change in configuration?

I've been working on a simple project that uses some common .NET classes, isolated storage, some resources and no external libraries.
Somehow the EXE generated (either in debug or release mode) no longer runs (stops working as soon as it's opened) without giving any details or displaying any exceptions.
It runs normally in visual studio, and there's a .application in the same folder that when clicked starts in install process.
I'm not interested in installation files, I just want it to be the way it was: running an EXE (it's easier to get testers when all you have to do is running it).
I have previous versions of the program, and all of them run normally through the EXE's.
I don't recall changing anything regarding framework, deployment or build. I revised it and there's nothing changed apart from using new objects from the .NET framework.
--[Update]--
Just checked the event viewer. Event data "not available" and answer "not available".
This is a classic example of when a personal version control system would have helped. It would have automatically kept every version of your code including the one right before you made the change that messed up your exe.
Anyway to fix your issue comment out the majority of the code untill it atleast runs. Add a simple output statement just to make sure it is doing something. Then slowly add back in more code.
I suggest you to run your exe file in a consol (cmd.exe) to see if your application displays errors or exceptions in it.
Check the <YourAppName>.Exe.Config file.
Probably it is not well-formed Xml.
I'd start with removing the setup project from the solution, rebuilding then run it in debug mode.

C# Updater for Windows App

i developed an updater application for my windows app. They are different projects under the same solution and they run as different processes. when i run the app it checks for updates at startup (as another process). when i click update button it tries to download files to the installation location. (i am using the .exe in debug folder i don't create setup file) Everything works fine but the main application (app.exe) can't be overwritten because it is used by update process. but in update process i kill app.exe and app.exe goes from task manager too. i couldn't find anything, how main app.exe is used by update. has anyone any idea how update uses main app ? how can i watch it? in which line it starts using the other app?
Rename app.exe
Insert new app.exe
Close running, old app.exe
Start new app.exe
Check for renamed app.exe (in newly started app.exe)
Delete old, renamed app.exe
If the updater app has a reference to the main app exe, it will keep it locked. If that's the case, can you remove the reference to the main app from the update app project? This may need moving some code directly into the updater's source.
To find out who has a hand on your process you should start ProcessExplorer. There are some spy glasses in the menu bar. Just click on it and see which process holds a handle to your app.
Do you need to invent your own? There are existing solutions that you may be able to leverage that already do this. Microsoft ClickOnce supports this if it fits your deployment model.
A quick google search turns up a few things as well:
http://csautoupdater.sourceforge.net/
http://www.codeproject.com/KB/vb/Auto_Update_Revisited.aspx

Categories