N
N
Nikita072020-04-25 17:31:34
WPF
Nikita07, 2020-04-25 17:31:34

Why is my WPF application crashing?

Hello everyone, the essence of the question is this:
there is an application on WPF, inside the Grid there is a button responsible for generating a report in Word, but for some reason after clicking on it, the program crashes, what could be the reason?

Button code from the test application, here it is enough to open Word, but the error still occurs

private void Button_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Document doc = app.Documents.Add(Visible: true);
            app.Documents.Open(@"C:\Users\Name\Documents\1.docx");
            Console.ReadLine();
            doc.Close();
            app.Quit();
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2020-04-25
@SaNNy32

It is necessary to understand under the debugger on which line it crashes and dance from there.

R
Roman, 2020-04-25
@yarosroman

https://github.com/UNIT6-open/TemplateEngine.Docx try this lib, why bother with your bike. There is an article about it on Habré, where it is written in Russian how to use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question