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

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.

Related

Publish WPF + EF Core App with Windows Installer Project

I have tried to create an .exe file to my WPF App and SQL Server related databse with EF Core using Windows Setup Installer Project.
I included all the dll's files from /bin/Release and built it for any CPU.
The Setup Project has been created successfully and it worked on my PC as I expected.
Otherwise when I try to install the Setup File on another PC, I can't even open it up and see what's wrong.
I guess the problem comes from the database but I can't find anything helpful on the internet.
So you get the application installed, run it and nothing happens, right? Here is what you do:
Run it. Watch nothing happen
Hit the Windows key and type "Event"
When "Event Viewer" appears in the list of applications, run it
In Event Viewer, go to Windows Logs >> Application
Near the top there will probably be an error entry. It will probably be related to your application. And if you were missing a key file needed to run your application, like a DLL, the name of the file will probably be in there in the details section
Go back to your installer and add that missing file. Or if that file is part of some support package (like, say, MS Redistributable for Visual C++) then add the installer for that too.

WPF application installed in program files just exits - but runs in another folder

Using Visual Studio 2017 on Windows 10, I have a WPF application with an installer created using the Visual Studio Installer extension. When I install it on another PC, the application starts but then exits within the same second. Nothing in logs.
If I add a manifest to force admin mode, its starts correct.
If I copy the files to another folder (outside program files) it starts correct.
Apparently the "program files" is restricted or something? Am I missing something in my setup/installer project? Any other ideas more than welcome!
EDIT:
I've tried to create the installer using WIX and then it runs fine. Seems to be some settings in the VS Installer extension.
You can modify the ACLs on the folder in question to allow write access by regular users (not great) or you could write the settings file somewhere else where write permission for users is standard.
There are many ways: Resolve lacking permissions.
There is another, similar answer here.
Adding a couple further links:
WiX and deployment links, various topics.

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.

Issue Signing xap file in post build event on TFS Build

We have a silverlight(5) project, the source in TFS (2010) and Continuous Integration build has been setup and working fine. However, we are now at the stage where we are trying to release it to some users to get them using it and give feedback. I've set up the code so that it checks for updates and if there are any it downloads the latest xap file. However this requires the xap file to be signed. No problem when doing this from our dev machines, but when it comes to the automated build it fails, with the message
Xap packaging failed. Cannot locate the signing tool SignTool.exe.
I've tried numerous things to get the signtool to be recoginised and can't. However, we don't actually need this on the CI build, so I've then tried a second tack which is to make the postbuild event conditional on being run in VisualStudio. Followed various suggestions here on SO but can't gett them to work.
The post build event is
if "$(BuildingInsideVisualStudio)" == "true" (
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe" sign /f "$(SolutionDir)castle.pfx" "$(TargetDir)Castle.xap"
copy "$(TargetDir)Castle.xap" "$(SolutionDir)Castle.Web\ClientBin"
)
still no joy. Have tried multiple variations of this, but keep getting the same message from the automated build.
So can anyone help with either a) getting the signing tool to be recoginised on the build server or b) getting the automated build to skip the postbuild event?
Found the problem in the end...
I had been putting in place some features so the app would download and install the latest xap file. This requires it to be signed. As this wasn't working I followed some instructions on signing a xap file, not realising that one of the other developers here had put in place the code I described above in the post build event.
I had mistakenly thought that this was created as a result of me checking the 'Sign The Xap File' check box.
So first issue was that other developer had not shared his pfx file with us to add to our certificate stores.
Second, and main issue, was that we then had two attempts at signing going on. The one via the check box and the one via the post build event. I removed the check box and it worked fine.
The issue with the check box is that it expects the SignTool.exe to be in a particular location. On our development boxes with full VS it is where it is looking for it, but on the build server it wasn't. Think it may also have something to do with 64bit machines.
By using only the build event (once you have the correct certificates installed) you can specify explicitly the location that the signtool is going to be, and if necessary install the windows sdk to that location.
This is the top result in Google for this error so updating it with my steps to resolve.
The above didnt work for me but performing the steps below should fix it.
Install the Windows 8.1 SDK on the build server (Windows 2008 R2 for me)
Adding the Windows SDK BIN directory (that contains signtool.exe, on my server) to the Environment PATH variable - e.g. c:\program files (x86)\Windows Kits\8.1\bin - note: Do not add quotes around this
Restart all the Visual Studio Team Foundation services in services.msc after you add the file path to the PATH variable as it needs to reload these before building

IIS related System.ExecutionEngineException

After too many hours of research I have come up with nothing to solve this problem.
I am running a WPF program in an .xbap page file being hosted on internet explorer. Running the project in Visual Studio 2010 works just fine and generates no errors.
I want to be able to host the webpage on IIS 7.0 and to browse to it with a windows forms application. To test this I created a new website on port 80 in IIS manager. I then published the project to the local website folder and added the autogenerated project certificate file (projectName_TemporaryKey.pfx) to my Trusted Publishers and Trusted Root Certification Authorities.
My problem is this: whenever I try to browse to the file with internet explorer or with my windows forms program, the wpf program stops working. When pulling up the just-in-time debugger, I am informed that there is a System.ExecutionEngineException but am given no source code, no stack trace, and no data outside of an empty Dictionary enumerable. My guess is that this might have something to do with the database call made in the program to another machine, but I can't prove that.
I've tried several things to solve this including repairing my .NET 4.0 framework and altering permissions but nothing seems to be affect the error.
Does anyone know of a way to get more information on this error, or perhaps a step I may have missed when publishing this project?
Thanks very much.
Some things to check:
Windows event log often includes additional exception information (although usually in an awful format)
Output some trace information from your application so you can follow what's happening
Try attaching a debugger to the WPFHost and then stepping through the code

Resources