VS2012 crash when user control attempts to access file - winforms

I am building a windows forms application (C#). I have created a reasonably complex custom user control, works great. Problem is, when I add this control to my main form it crashes VS some time later.
After looking around about this I found the suggestion that I use two instances of VS, one to debug the other - this quickly narrowed in on the problem:
The custom user control contains a 30 second timer which saves some data to an XML file when it completes. As the program is not actually running, it is attempting to save the file to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE , where it does not have permission (thus the crash).
This is an unusual problem, as when the application is running normally it will not be a problem (the file is set to save in the same directory as the executable). Is there a way to prevent the control from running while in design mode?

Related

running Winform Application

detailed message box texti made a winform application on my pc and it runs fine. but when I tried to run it on another PC by copying the exe file and other dll files there , the application failed to run and all of a sudden it shows a dialog box to close the aplication.
please refer to screenshot of error.
enter image description here
Like bassfader said: One possible explanation is that your application is handling files during startup. In that case: integrate more extensive exception handling for those parts. Potentially with logging, to locate the problem
In my experience this however is more often a case of missing some kind of dependency.
Double check .NET runtimes. Lookup the target .net version in Visual Studio and run the installer on the target machine.
Investigate if your app uses any assemblies that are not part of the .NET framework. Sometimes these are not copied to the bin directory if they are in the GAC (ensure the flag "Copy Local" is set to "Always" in Visual Studio)
Ensure you have copied the whole bin folder
Check compiler output to see if you've got Platform mismatches. IIRC this can sometimes work fine on a dev machine but cause problems when Visual Studio is missing or you get to a different OS.

How does a WinForms .Net sub-application in a solution embed its app.config into itself?

I am using a variation of Jeff Atwood’s Unhandled Exception handler it steps in when there is an Unhandled Exception in the application. It then logs the error, generates a screen shot and notifies the user.
When compiled in a solution the project generates an EXE that is called when needed. In updating the program I am using Visual Studio 13 to edit the existing settings items in the project properties. In the code I use commands such as this from ConfigurationManager.
string appProduct = unhandledExceptions.Properties.Settings.Default.AppProduct;
I was happy to see that it worked and reflected the changes I made in the IDE. However I couldn’t find the settings in the solutions generated confg file (MyApplication.exe.config). I assumed it was reaching back to the other project folder for the UnhandledExceptions.exe.config.
I created an installer and installed it to a virtual machine. My settings carried over, but again I could not see a config file.
It turns out the values are embedded in the executable UnhandledException.exe.
The project does not have any resources listed. Searching the web and StackOverflow looking a questions that want to do this, and there are a lot of them, it seems this was generally considered not possible and not desirable. Questions usually end in “You don’t want to do that, it’s called config for a reason”.
I may want to turn this off, so it is editable externally. The properties of app.config in both projects are identical.
What setting is making this possible after all? Is it a new capability with Visual Studio 2013?
There is no Visual Studio setting required. If you don’t want the user to have access to the configuration file, don’t include it in the distribution. One can always be added if the settings names are known.
In the description below application generically represents the name of the application being used.
I’ve found through observation some interesting things about the way ConfigurationManager works.
For User settings it will look in the following places in order of priority:
user.config for the application in the user’s AppData area
application.exe.config in the program folder
application.exe itself
Each setting is searched for individually. If your application requests a setting that is not found in either user.config or the application.exe.config it will get it from the executable.
For Application settings it looks in the following places in order of priority:
application.exe.config in the program folder
application.exe itself.
There is no equivalent to user.config for application settings.
Opening the application.exe in the Visual Studio IDE does not reveal a resource for the configuration information.
application.exe.config is handy because it can be modified externally and used as a default value for new installations. Once a setting is overridden in the user.config the value in application.exe.config is ignored.
The same is not true for the AppSettings section, the older configuration method from .Net 1.0. If I delete the configuration file it does not have them in the executable.
These observations were made with Visual Studio 2013 Update 4 and tested in Windows 7 Professional 64-bit. I suspect they are true in all versions.

VB.Net Transferring A Windows Form App Onto A USB Stick

I am just wondering how do you transfer a windows form application onto a flash drive because every time I have tried after its transferred I click to open it and an error message displays saying:
"Cannot find the file 'F:\Vending Machine.vb.'
I need to be able to transfer it so when it opens I am able to edit the code and the appearance of the application as I would if I were to just open a new windows form application now.
Thank you
Marcus.
You will need to transfer the entire project/solution to the USB.
Transfering the already compiled .exe should open the latest build of your application. Transferring only a portion of the solution folder and then trying to open the .sln will cause errors on the files you have left out.
Clear your FlashDrive
Copy the entire folder(not the contents) to your flashdrive (C:\Users\Marcus's MPC\Documents\Visual Studio 2010\Projects\Vending Machine)
Attempt to open the .sln
Based on your additional comments it seems you are not moving all of the files the solution needs. If you have files stored in other locations (like My Document) those will need to be reconfigured to work with the solution or you will have to mimic the environment.
I would recommend reconfiguring the project to consolidate any stray files you have.

WPF app won't run in kiosk mode

I have a WPF application that is designed for a touchscreen kiosk. Users will not have access to a keyboard or mouse. The application runs fine when started normally from the program icon in windows. However, when it is set up to run automatically at startup (by replacing the Windows shell using a registry key), the application does not function properly.
The application reads an XML file that lists available videos, then displays buttons to show the videos. When run in "kiosk mode," it does not seem to have access to the files in its media directory (the XML file and presumably the videos as well). I suspect that because the application is running in place of the windows explorer, it is missing resources it needs for file access that are normally loaded by windows explorer.
I have not been able to find any info on this - there is plenty of info on how to get an app to run at startup, but not much on how to make sure it will actually function in that environment. The PC is running Windows 7 Professional.
Is my assumption about the problem correct, or is it likely something else (e.g. permissions - we checked the permissions, but maybe they operate differently when you replace the windows shell?) If it is because needed resources are not loaded, does anyone have pointers on how to make sure my app loads them?
Perhaps you have file access occurring via a file dialog? This might explain a bit further. What is the minimum functionality needed to create Shell Replacement for Windows?
because you have stopped windows default running explorer.exe , your program can not get access to default xml directory therefore you should specify the complete path for example like below:
stream = File.Open(#"C:\x86\Debug\xml.xml", FileMode.OpenOrCreate);

WPF application using win32 dialogs on XP crashes

We have a WPF application that was developed on Windows 7 using VS 2010 and .NET 4.0 framework.
I have created an install package for it using the Visual Studio Installer.
When running on XP it appears to go into a bad state after using the win32 OpenFileDialog. It took me a while to track this down, as it doesn't fail right away. The dialog appears, you select the file you want to open, it opens up and is displayed on the screen. I was using it for about two minutes and then it crashed. I get the message that my program has encountered a problem and needs to close.
I can now run my application, open a file and make it crash right away, since a specific action always makes it crash. It does on any file I open, even a new one.
So I tried opening the same file without using the OpenFileDialog, I have a MRU list that I selected the file from, and it works flawlessly. I have not been able to make it crash.
Anyone experience similar behavior or have any ideas?
Since I do not have a debug environment on the XP machine I tried putting in some tracing statements within the application to write out to our log file where it is and what value some variables have. The really strange thing is that as soon as the OpenFileDialog.ShowDialog method is called all writing to our log file stops. I am just using standard file I/O and actually open, write and then close the file for every log message. This makes it difficult to debug this way, but also further supports the fact that something is gone wrong in the environment.
I have tried on four different XP machines, all with the same results.

Resources