0

I wrote a program with .Net 4.0 in C#, and it works well in the two computers in which I compiled it. But when I copy the program into other's computers, the program even didn't show it's UI, and gives out a MessageBox like this: enter image description here

The box says my program has cause an APPCRASH. Anyone has any idea how to fix the problem?

sparrow
  • 41
  • 1
  • 8
  • 1
    You sure they have proper .NET version installed? – Euphoric Feb 19 '14 at 07:10
  • The program has an unhandled exception. You can add some exception logging, either to a log file, or event log (might be more difficult due to privileges, not sure) to obtain the info you need to fix the bug. – Dmitriy Khaykin Feb 19 '14 at 07:12
  • First, thanks! And I am sure I have the proper version of .NET installed. I test this in a virtual machine. – sparrow Feb 19 '14 at 07:13
  • Could you print the Stacktrace? You can find them inside the event logger of windows in application. – Andre Hofmeister Feb 19 '14 at 08:44

3 Answers3

2

Could be several reasons. One of the more common ones is that you're compiling it for a .NET framework that the target machine does not have. Another could be that you're compiling for 64-bit, while target machines are 32-bit.

Some of the steps to fix this:

If you're using Visual Studio, right click on your project and go to Properties. In Application tab check to see which Target framework is being listed. It could be .NET Framework 4.5.1.
Change it to .NET Framework 4 Client Profile and see if it runs on your target machines. Also, under Build check to see which Platform target options you have selected and adjust accordingly. It might be helpful to select x86 rather than Any CPU.

Other thoughts/tips:

From the screenshot, it appears that you're running it on Windows 7 machines, so I doubt that .NET framework is the issue; in that case, ensure that target machines contain all the appropriate libraries that you're using. If you have some non-native libraries, make sure that you set Copy Local to true for them.

By the way... when you say you copy it, I'm assuming you're copying all the appropriate files along with the executable, right? There might be some files, such as libraries, app configuration files, etc., that you need to copy along with it.

David Khaykin mentioned the fact that you might have an unhandled exception there. Therefore, as suggested in this SO thread, you may want to implement an event handler for the AppDomain.CurrentDomain.UnhandldedException event and check the value of the e.ExceptionObject.ToString().

Here's MSDN link to help you with that (scroll to the bottom to see an example): http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.110).aspx

Some ways to analyze crashes:

Here's a neat article that describes how to analyze your crashes:

http://blogs.msdn.com/b/anandbms/archive/2005/04/20/410225.aspx

It uses AdPlus, which you can read more about and obtain at http://support.microsoft.com/kb/286350

Here's a more direct link to WinDbg debugging tool: http://msdn.microsoft.com/en-us/windows/hardware/hh852365 (scroll down halfway and make sure you get the Windows 7 version if that's your OS).

Those are just some of the things that I've done over the course of my C# adventuring, so hopefully one of them can help you.

Community
  • 1
  • 1
B.K.
  • 9,982
  • 10
  • 73
  • 105
  • Thanks a lot! But I have tried this, and it didn't work. My settings are proper. – sparrow Feb 19 '14 at 07:19
  • In fact you found the reason of my problem. The program lost a lib which should be copied automatically by the compiler. It is very strange. Before I found that, I tried your methods, and learned a lot. – sparrow Feb 19 '14 at 13:22
  • @sparrow I figured that's what it was. Great job! Glad I could help. And don't forget to mark the correct answer if it helped you. – B.K. Feb 19 '14 at 16:48
2

I encountered this issue once (APPCRASH referencing kernelbase.dll), in my case I had an issue due to a corrupted user profile (no certain cause for it , but I experienced a couple of blue screens before) which prevented some (but not all!) of my applications to abruptly not work anymore: to verify it, try creating a new Windows user on the faulty computer, copy the application over and attempt to execute it.

Alex
  • 23,004
  • 4
  • 39
  • 73
1

I checked the event log in my target machine, and foud some useful information. The information is just next to the "APPCRASH" one, and it says like "can't find a file...". Then I checked my program and found a lib haven't been copied there by the compiler.

It seems the event log can really help.

Thank you all who cared!

sparrow
  • 41
  • 1
  • 8