Error Object Reference not set to an instance of an Object. Microsoft.Office.Interop.Word.Application

Asked

Viewed 291 times

0

I am developing a code to convert a word document into pdf. When I run the application through Visual Studio, the conversion is performed and no errors are shown. When I run the application on the server where IIS is installed, the document is not converted and an error is returned.

Code:

            // Abrir Aplicacao Word
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();

            string WordFile = @"c:\Projetos\Conversoes\Word.docx";

            object filename = (object)WordFile;

            // Arquivo de Destino
            object newFileName = @"c:\Projetos\Conversoes\ArquivoConvertido.pdf";

            object missing = System.Reflection.Missing.Value;

            object onlyread = false;

            // Abrir documento
            Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref filename, ref missing, onlyread, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);

            // Formato para Salvar o Arquivo – Destino  – No caso, PDF
            object formatoArquivo = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

            // Salvar Arquivo
            doc.SaveAs(ref newFileName, ref formatoArquivo, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

            // Não salvar alterações no arquivo original
            object salvarAlteracoesArqOriginal = false;
            wordApp.Quit(ref salvarAlteracoesArqOriginal, ref missing, ref missing);

            Marshal.ReleaseComObject(wordApp);

Error:

Message:

[1] Exception of type 'System.Web.Httpunhandledexception' was thrown.

[2] Object Reference not set to an instance of an Object.

Event:

[1] System.Web.Httpunhandledexception

[2] System.Nullreferenceexception

Local:

[1] Boolean Handleerror(System.Exception)

[2] Void Page_load(System.Object, System.Eventargs)

Source:

[1] System.Web

[2] Gesthos

Stack:

[1] at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(Iexecutionstep step, Boolean& completedSynchronously)

[2] at GestHos.Documentos.Conversor.Converter.Page_Load(Object sender, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

  • Yeah, I checked that out.

  • When I published the application it should already have gone, no? Anyway, how can I check?

  • You know how I can check if it was published?

  • Good.. in the project bin folder the DLL is not actually found. However, the development server, where it is working, is also not found.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.