如何解决.NET运行时1026 [英] How to solve .NET runtime 1026

查看:3523
本文介绍了如何解决.NET运行时1026的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#程序,它使用System.Runtime.InteropServices来调用Excel宏。该程序在任务计划程序中运行,通常无故障运行。但是,偶尔,我从程序中获取事件ID 900我的未处理异常逻辑,然后是.NET运行时事件1026,然后是应用程序错误1000.

未处理异常结果:





.NET运行时事件1026





应用程序错误1000





我的尝试:



我添加了信息消息到事件日志,以显示失败的代码中的语句是:oExcel.Run(Mname);完整的代码块是:

static void GetExcel(字符串Fname,字符串Mname)

{

string sEvent;

string sSource =CFHIMA_CallMAcro;



object oMissing = System.Reflection.Missing.Value;

sEvent =GetExcel 01 ;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



Excel.Application oExcel = new Excel.Application( );

sEvent =GetExcel 02;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



oExcel.Visible = false;

Excel.Workbooks oBooks = oExcel.Workbooks;

sEvent =GetExcel 03;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



Excel._Workbook oBook = null;

sEvent =GetExcel 04;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



oBook = oBooks.Open(Fname,oMissing,oMissing,

oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,

oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);

sEvent =GetExcel 05;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information, 0);



oExcel.Run(Mname);

sEvent =GetExcel 06;

EventLog .WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



oBook.Close(false,oMissing,oMissing);

sEvent =GetExcel 07;

EventLog.WriteEntry(sSource,s Event,EventLogEntryType.Information,0);



System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);

sEvent =GetExcel 08;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



oBook = null;

sEvent =GetExcel 09;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);

sEvent =GetExcel 10;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0) ;



oBooks = null;

sEvent =GetExcel 11;

EventLog.WriteEntry(sSource, sEvent,EventLogEntryType.Information,0);



oExcel.Quit();

sEvent =GetExcel 12;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);

sEvent =GetExcel 13;

EventLog.WriteEntry( sSource,sEvent,EventLogEntryType.Information,0);



oExcel = null;

sEvent =GetExcel 14;

EventLog.WriteEntry(sSource,sEvent,EventLogEntryType.Information,0);



}

I have a C# program that uses System.Runtime.InteropServices to invoke an Excel macro. The program runs in Task Scheduler and usually runs without incident. However, occasionally, I get Event ID 900 from program my unhandled exception logic, then .NET Runtime event 1026, then Application Error 1000.
Unhandled Exception result:


.NET Runtime Event 1026


Application Error 1000


What I have tried:

I added Information messages to the Event log to show that the statement in code that is failing is: oExcel.Run(Mname); The complete code block is:
static void GetExcel(string Fname, string Mname)
{
string sEvent;
string sSource = "CFHIMA_CallMAcro";

object oMissing = System.Reflection.Missing.Value;
sEvent = "GetExcel 01";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

Excel.Application oExcel = new Excel.Application();
sEvent = "GetExcel 02";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oExcel.Visible = false;
Excel.Workbooks oBooks = oExcel.Workbooks;
sEvent = "GetExcel 03";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

Excel._Workbook oBook = null;
sEvent = "GetExcel 04";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oBook = oBooks.Open(Fname, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
sEvent = "GetExcel 05";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oExcel.Run(Mname);
sEvent = "GetExcel 06";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oBook.Close(false, oMissing, oMissing);
sEvent = "GetExcel 07";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
sEvent = "GetExcel 08";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oBook = null;
sEvent = "GetExcel 09";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
sEvent = "GetExcel 10";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oBooks = null;
sEvent = "GetExcel 11";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oExcel.Quit();
sEvent = "GetExcel 12";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
sEvent = "GetExcel 13";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

oExcel = null;
sEvent = "GetExcel 14";
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0);

}

推荐答案

我会说你的宏出了问题 - 也许在Excel中出现未处理的异常?只是一个猜测......

如果您遇到错误,请查看宏中是否出现问题......
I'd say something goes wrong in your macro - maybe an unhandled exception occurs in Excel? just a guess though...
Have a look if you can find out if something goes wrong in the macro if you encounter the error...


Put在 oMissing 的定义之后, try / catch 阻止所有内容。此时,您可以检查 sEvent 以查看它失败的位置。
Put a try/catch block around everything after the definition of oMissing. At that point, you can inspect sEvent to see where it's failing.


这篇关于如何解决.NET运行时1026的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆