views:

1611

answers:

3

I have written a very simple C# Console Application which will open a Crystal Report, refresh it and save it as a PDF to a specified location.

When running within VS2005 everything runs fine; the pdf file is generated as expected. When I copy the .exe to my root C: drive and run it from the command line I get a dialog box stating that "CrystalGenerator has stopped working" - but the pdf file is still generated! Looking up possible causes of this dialog indicate that an Unhandled Exception has occured but the entire contents of the Main method is contained within a try/catch so that can't be my problem.

Looking in the event log I see a number of entries stating "The substitution string for insert index (%1) could not be found" but cannot find a sensible explanation of what this means.

The upside is that if I copy the file to a box running Server 2003 (where it is intended to run) the command runs without error - but I want to know why the app misbehaves on Vista and how to resolve it.

Thanks in advance.

+1  A: 

Does it work if you run the app from an elevated command prompt (WinKey followed by pressing cmd followed by Ctrl+Shift+Return)?

It might be that one of processes you are calling requires elevation.

0xA3
@divo: thanks for your suggestion but no luck I'm afraid.
DilbertDave
It seems the error that you are seeing is related to a problem with event log in Vista: http://blogs.msdn.com/ericfitz/archive/2007/04/18/vista-security-events-get-noticed.aspx (see the first comment)
0xA3
Did you check that when debugging the debugger stops at all exceptions? Have a look at Debug -> Exceptions... and see whether all boxes are checked.
0xA3
I Enabled Unmanaged Code Debugging and now get the following error in VS2005: Unhandled exception at 0x074abc38 in CrystalGenerator.exe: 0xC0000005: Access violation. Googling!
DilbertDave
it's throwing the exception on the following line: ReportDocument oRtp = new ReportDocument();
DilbertDave
Please consider editing your question - sounds like Vista may have not been the culprit but actually revealed a problem.
Argalatyr
@Argalatyr: Good call - title updated.
DilbertDave
A: 

Well after a lot of link-chasing it looks like this behaviour is 'By Design'!

StackOverflows own Jeff Atwood experienced the problem (see here) and raised the issue on Microsoft Connect (see here).

Looks like I will be looking for an alternate approach - although the code does work on Server 2003.

Thanks to divo for your suggestions which were very helpful.

DilbertDave
+1  A: 

If for whatever reason, you are causing a stackoverflow, it cannot be caught, because there is no way to reliably unwind the callstack.

In that situation, your application will behave like you said.

FlySwat