开发者

WPF application throws an exception after printing to file via doPDF printer

I have made a wpf standalone application for accounting purposes. The application works and prints well to an external printer or microsoft XPS printer. The problem arises when i select doPDF(an application which outputs a pdf file) as printer. The output is just fine; it creates the pdf file and saves it, but, when i come back to the application and press any button, an XamlParseException was unhandled error is thrown which says

'The invocation of the constructor on type 'RegisterMaintenance.DisplayInvoice' that matches the specified binding constraints threw an exception.' Line number '5' and line position '7'

InnerException: Verify that the file exists in the specified location

InnerException开发者_如何学C: When using relative paths, make sure the current directory is correct

Why is this happening and what can i do to get rid of this problem.


Seems that this pdf printer changes the current directory for the process. I can think of 2 possible workarounds for your problem.

The first and most obvious workaround for your problem would be to use a absolute path for "Transactions.xml" and store this in your app.config. This might however become problematic if your application is ditributed to various different machines and installed in different locations.

The second workaround is to temporarily store your current working directory before calling the print function, and then restore it afterwards, if it has changed. Something like this:

string path = Directory.GetCurrentDirectory();
//Do the print stuff
Directory.SetCurrentDirectory(path);


Seems like most probable cause is that some resource is not found or already occupied. Please share your code for Line number '5' and line position '7' with us.


You can use your debugger and set a breakpoint on line number 5 where the constructor for RegisteMaintenance.DisplayInvoice is called. Look at the file path being used and fix the problem. Alternately, if you're highly confident it's not a problem you can try/catch and ignore the exception but I don't really recommend that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜