WPF C# application deployment - Nothing happens when running the exe - c#

I've copied over the content of the Debug folder on a Windows 7 VM and a Windows Vista laptop. Both had Dot Net 4.5 installed. All assemblies are set to copy local and AFAIK I don't reference anything not in the application folder. When I run the app on the two different developer computers (one Win8, one Win7) it runs fine as it does when running it in Visual Studio (F5).
Not so on the deployment computers. The problem is that I get no error message. Absolutely nothing happens after I double click the executable on the non-development machines.
I tried starting it in WinDbg.exe and got this output: http://pastebin.com/43PbwyGx
So how to I go about debugging this to find out what's missing?

looking at your WindDbg dump you have an 2nd Chance Execption of CLR exception - code e0434352 (!!! second chance !!!).
I would look at this article by Igor Dvorkin, Why do I keep getting exception code e0434352.
Where he discusses it being a generic exception and how to fire up the cdb to find what the underlying exception was.
He also links to another of his blog posts, Finding CLR exceptions without visual studio where he describes using cdb.

Are the dev machines 64-bit but the other machines 32-bit? If this is the case and you're building as AnyCPU, then all your references also need to be AnyCPU (or match the platform your program is running under). If you build as x64, then I think all your references need to be x64 as well, and the same goes for x86.
Usually the exception you'll see in this case is a BadImageFormatException (it's also typically logged to the Windows Application Event Log with a source of Side By Side Configuration).
Also, just an FYI, sometimes you might be able to find the exception in the Windows Event Log. I think it's the Application Log, and I think the Source is usually .NET Runtime, or Application Error. The details may include both the actual exception as well as a stack trace.
I'm not sure what conditions need to be true for these errors to be logged, but it's something to consider.

Related

InvalidProgramException / Common Language Runtime detected an invalid program

This is the strangest programming issue I have seen in a long time.
I am using Microsoft Visual C# 2010 Express, C# and .NET 2.0 to develop an application. This application references a couple of dll/assemblies (those dlls are all generated on my machine).
Below is part of the code (it is all basic stuff):
public class PowerManagement
{
[TestCase]
public void PrepareTest(){
// Configure according to pre-conditions
Preconditions precondition = new Preconditions();
precondition.SetupPreconditions();
...
}
[TestCase]
public void PerformTest(){
TestcaseData testcaseData = new TestcaseData();
// Set Trigger and perform check
switch (testcaseData.triggerNumber){
case (1):
if ((new Trigger1(testcaseData)).Validate() != 1)
Report.TestStepFail("failed");
break;
...
case (4):
if ((new Trigger4(testcaseData)).Validate() != 1)
Report.TestStepFail("failed");
break;
default:
Report.TestStepFail("Not yet implemented");
break;
}
}
}
This application is then generated into a dll from Visual C# 2010 Express and used elsewhere and all is fine. The problem surfaces when I add another case to the switch-statement above (see below)
...
case (4):
if ((new Trigger4(testcaseData)).Validate() != 1)
Report.TestStepFail("failed");
break;
case (5):
if ((new Trigger5(testcaseData)).Validate() != 1)
Report.TestStepFail("failed");
break;
default:
Report.TestStepFail("Not yet implemented");
break;
I can still build without a single issue and generate the dll but when I use the generated dll I get the following error:
A .NET exception (InvalidProgramException) occured in the module PowerManagement
Error message: Common Language Runtime detected an invalid program.
Throwing method: PowerManagement.PerformTest
(the issue happens even if I copy case(4) and paste it as a new case, so it has nothing to do with Trigger5-class)
What is happening here? I have looked through the other InvalidProgramException and Common Language Runtime in Stackoverflow but none seemed related.
I know this issue is strange so please let me know and I will provide more information. I am using a 64-bit Windows 8 machine, if that matters. I have already checked for any updates on VS and .NET updates. I havet also regenerated all the dlls a couple of time ans also created the solution from scratch a couple of times.
Just wanted to add my experience for this...
In my case, I am hosting my C# Web API on Azure and I encountered this message when trying to log in to my API.
I had to go into my Azure management portal (portal.azure.com), go to App Services, choose my Web API program and click Restart from the Overview screen.
After this, the program worked as normal again.
Did not find any further clues in my logs.
I finally managed to solve this issue.
I unchecked code optimization in C# Express and that solved the issues. Still the weirdest thing, but since we are using old tools and framework we can not really blame anyone.
Try enabling 32-bit applications in your application pool advanced settings.
I had this problem after upgrading to Visual Studio 2017 v15.8.6. The problem went away when I removed the assemblyPostProcessorType attribute in the compilation tag in web.config.
According to MSDN: "Generally this indicates a bug in the compiler that generated the program."
I would start by making sure you have all the updates installed on Windows, .NET and Visual Studio.
You should also check out Q312544 on Microsoft Support.
I've occasionally encountered this error after a deployment to an Azure WebApp using MSDeploy. The error has always disappeared after redeploying for a second time.
Our build and deployment are two different steps, the the redeployment is sending over the exact same files each time - this suggests the problem is not uniquely a compiler issue as suggested elsewhere in this question's responses.
Could be a bug in MSDeploy, or in the version of IIS used for WebApps in Azure perhaps...
Such problem could be caused by bugs in tools manipulating the IL of assembly after compilation, for example if you are using Fody and its plugins. At least there is a bug in Fody MethodDecorator which causes such effect, see
https://github.com/Fody/MethodDecorator/issues/8
If you are having this issue specific to Azure Web Apps - check for installed extension Microsoft.ApplicationInsights.AzureWebSites - or it's friendly name Application Insights extension for Azure App Service and remove it via kudu.
We found this extension was potentially interfering with msdeploy pushes - there was a process snapshotholder_x64.exe running under the IIS w3wp.exe process. Someone likely enabled this extension via the azure portal.
If your issue pertains to a web api dotnetcore deployed to an azure app then this could be caused by application insights. Setting the application insights at the blade level should fix the problem. Also note that there seems to be an unresolved issue with setting it at the blade level as recommended settings vs basic. Basic being the value that works.
Running into this issue deploying a Web Api as an API App on Azure. An initial request to any endpoint would result in the expected response; however, subsequent requests would return the same Common Language Runtime error. I figured out the problem started when I enabled Recommended collection level on the Application Insights blade on my web app. I set recommended and enabled all radio buttons. Reverting this change stopped the error. For reference, the API I am running is running Microsoft.ApplicationInsights 2.8.1
For reference:
https://github.com/dotnet/coreclr/issues/18323
I was doing some powershell automation in a console application using .net core 3.0 when i started receiving this error. I guess .net core is not compatible with System.Management.Automation so i changed it to .net framework 4.7, everything worked well after that
I resolved this issue by doing the following:
Rename C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Performance Tools\vsinstr.exe to C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Performance Tools\vsinstr.exe.broken
Rename C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Performance Tools\vsinstr.legacy.exe to C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Performance Tools\vsinstr.exe
Rebuild the solution
-uncheck "code optimization" (referenced dlls included)
-Upgrade to .net framework 4.6
Out of nowhere we started getting XXX webservice Exception , System.InvalidProgramException: Common Language Runtime detected an invalid program.
Copied compiled website to a different environment - works just fine.
Copied to a different server - works just fine.
I noticed that this exception started when server was reset (either rebooted or app pool reset). When researching this issue, I noticed comment by Brian Reichle on Jun 6 '16 at 12:33
I would expect a bitness mismatch to result in a
BadImageFormatException rather than the InvalidProgramException
described in the question.
I was not familiar with InvalidProgramException exception but I was familiar with BadImageFormatException and the symptom is very similar to the one I get with BadImageFormatException issue. I can't say 100% why either exception happens, current running theory is its a 32-bit application running on a 64-bit machine, but we couldn't prove it nor could we perma-fix it. Enabling 32-bit applications on app pool did not fix the issue.
The only fix we know of, albeit temporary, is to simply recycle App Pool. No need to recompile or anything. Luckily, this happens not too often, maybe once a month or two.
I just ran into this problem myself. Even though VS created the virtual directory for me, it had vb as the default language, but I have a C# application. Changing this setting solved it.
This is an interesting exception that i came across while hosting on IIS. I solved it after finding out that my .NET Framework version on IIS was different from the .NET Framework version that my project was using. Please note if you happen to have other referenced projects/ddl(s) make sure you update their .NET Framework version too.
In my case it was Hasp protection (google: hasp sentinel protection key) SW which ruined the dlls.
To share my experience: had the same issue on x86 computer with my WindowsForms app, found out I've forgotten to copy .exe.config file with all dll redirections, after that everything worked like a charm.
In my case, the exception was caused by datadog tracer after upgrading from 3.1 to NET 6, by upgrading to their latest version, the issue was fixed.
Here is the diff in my dockerfile.
-RUN curl -LO https://github.com/DataDog/dd-trace-dotnet/releases/download/v1.12.0/datadog-dotnet-apm_1.12.0_amd64.deb
-RUN dpkg -i ./datadog-dotnet-apm_1.12.0_amd64.deb
+RUN curl -LO https://github.com/DataDog/dd-trace-dotnet/releases/download/v2.14.0/datadog-dotnet-apm_2.14.0_amd64.deb
+RUN dpkg -i ./datadog-dotnet-apm_2.14.0_amd64.deb
https://github.com/DataDog/dd-trace-dotnet

How do i debug C# windows form applications in production?

I developed a small app used to synch data between a local computer and an online web service.
In the testing environment, using visual studios 2012 express debug mode, I'm not able to reproduce a bug that is causing the application to crash.
I've tried logging activity manually by writing data to .txt file to give me a frame of reference, but I still can not determine where this bug is occurring.
Are there any tools available for debugging this app while in production mode?
If you can start a process on the remote production machine, the simplest thing to do in this kind of scenario is using the VS remote debugger.
This way you'll have a full debugging context with much more information than with simple logging; the debugging experience is (almost) the same as with local debugging.
It's a shame this tool is not widely known because it can literally save you hours or even days for tricky bugs.
Try logging stacktrace a.s.o. in AppDomain.UnhandledException event handler.
Furthermore it's possible to trace all function calls utilizing aspect oriented programming with PostSharp. There are examples on the PostSharp webpage.
We use Microsoft Enterprise Library to log and email the stacktrace to us any time an unhandled exception occurs.
Simply use NBug library which can catch unhandled applications and send a bug report to an e-mail address that you specify.
Yeah, the problem could be related to environment or the version of the software your debugging is not the same as production. So what you ideally want is to debug the live version against the same source code version and debug symbol files.
There are numerous articles on the net regarding how to do this like this one and this one. I read one once that showed you how to not only setup a symbol server correctly with TFS but on how to debug an production exe and VS would load the correct symbols for that version from the symbol server and the source code version from TFS... but alas i cannot find it.
The remote debugging an logging is all great essential tools but when you're at the place you're at now - the right version of debug symbols and source code would probably help you more.

Getting the error "The 'VFPOLEDB.1' provider is not registered on the local machine" even after installing and registering the provider

Alright, so I've got a Windows service that has a FileSystemWatcher that watches an output folder for some Visual FoxPro database files. And it leverages the VFPOLEDB.1 provider to read those files. I cannot go away from this provider because it's being used in production.
However, I've never had to support this application before so that's why my development box isn't setup for it. Here is my environment:
Windows 7 x64
Visual Studio 2005
.NET 2.0 Windows service
so, when I first started getting the error I figured I just didn't have the provider at all, and I was right. So, I downloaded and installed it from here.
I then proceeded to drop the files in the folder again, but I got the same error.
I figured because it's an x64 machine I might be experiencing problems with it getting registered since it was probably dropped into SysWOW64, and it was as I expected, so I ran this command:
regsvr32 "C:\Windows\SysWOW64\mscomct2.ocx"
and it said it was successfully registered (which means about nothing LOL) but I dropped the files in again - same error.
I have not yet rebooted my machine, and I can if somebody has a compelling reason that's the problem, but generally speaking if the assembly is registered properly with regsvr32 that's not necessary. I've worked with a ton of COM objects and never have to reboot to get to the object as long as I've registered it.
Does anybody know another step I need to perform to get this thing registered?
It is registered as it should. It is your application that is compiled for AnyCPU Platform.
In x64 operating system this produces 64bit code and 64bit code could not access 32bit drivers.
Change your Platform to x86 and you will be fine.
EDIT
Two years later there is something to add to this answer. Now with Visual Studio 2013 the cheese has been moved. The article linked explain in great details how the compiler setup defaults has been changed. The AnyCPU target CPU with Prefer 32 bit means that your application works as 32bit app also in x64bit operating systems leaving practically no-room to x64 application unless specifically required.
With this new configuration becomes also important to remember what is posted in comments below by Mark Berry. If your (now 32bit) app needs to work in a IIS 64bit environment you need to set the Application Pool with Enable 32 bit Applications
I have desktop app (Win7 x64 VS 2015) - and kept getting the same error no matter what. I changed platform target to x86, installed MSI as admin etc - did everything I could google - and no luck. What helped me is to install MSI for Everyone instead of Just me - one of the last wizard's screen in the setup.
I have the same problem.
I install the VFP Ole DB Provider in my system and resolved.
download link
use Advantage OLE DB Provider,works for 32 or 64,here is the connection string

First-chance exception at 0x782260ec in xxx.exe: 0xC0000005: Access violation

My application crashes after some time but I can't find any pattern. I was able to get my hands on crash dump. Application runs on Windows Mobile 6.5. It is written in C#. It uses Imaging API, PInvoks and lots of threads.
When I debugged that dump with Visual Studio 2008, in output it displayed "First-chance exception at 0x782260ec in xxx.exe: 0xC0000005: Access violation"
Call Stack shows 2 entries. But I can't match any of them to call from my code.
windbg.exe indicates that this error occurs in "netcfagl3_5.dll"
Are there some special techniques to analyze dump files from Windows Mobile??
0xC0000005: Access violation means that one of your p/invokes are incorrect. The call tried to write to a memory area which it doesn't have access to (which is typical if the definition is incorrect).
Your dump should contain a stack trace too?
'First-chance exception' usually means an exception that has been handled by user code. If you're using the Vosual Studio & the Windows Mobile emulator for debug then you can turn off exception handling. Go to Debug > Exceptions and check the 'Thrown' column for Win32 Exceptions. Then run the program and try and get it to fall over again.
When the debug runs it will halt execution and break to the debugger when it hits that 'first-chance exception' allowing you to see what is causing that, and see if it's in any way related.
The 'netcfagl3_5.dll' library is part of .NET CF, not your code, which is why you can't match up the debug symbols.
You will need to download windbg, Visual Studio 2008 won't do Post Mortem .NET debugging.
If your development machine is 64-bit, see "How to use Windbg to debug a dump of a 32bit .NET app running on a x64 machine"
Otherwise, see Post Mortem Debug under Windows Mobile with WinDbg. also do some searching on "Windows Mobile Post Mortem Debug".
The best (by far) and easiest way, though is to reproduce this issue while running on the debugger. Post mortem .net debugging is NOT easy.
-PaulH

WPF Error on Non-Development PC - XamlParse

I have an error very similar to the one addressed in this question. I am trying to deploy a small c#/Xaml utility on 6 work machines. 4 of the machines run the utility successfully and 2 do not. All machines are windows XP and have .Net frameworks 1-4 installed (my app is compiled against 4.0 and all machines have both client and extended redistributables installed).
On running the utility, I get the standard "... has encountered a problem and needs to close." On viewing the error report contents, the problem seems to occur in System.Windows.Markup.XamlParse.
I have run .Net 4.0 online installer in "repair" mode and still I get the same problem. I have tried all the suggestions from the post linked above:
The file is deployed alongside a DLL which is present and correct.
UI cultures are identical.
All computers are up to date from Microsoft Update.
The assembly does not contain any external resources which are referenced in XAML.
I don't really know where to start with debugging this one. Any suggestions?
I would suggest setting up remote debugging on the machines that are having the problem and then adding this to the startup code:
while (!System.Diagnostics.Debugger.IsAttached)
{
Thread.Sleep(100);
}

Categories

Resources