net应用程序出现CLR20R3错误

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

这是因为.NETFramework1.0和1.1这两个版本对许多未处理异常(例如,线程池线程中的未处理异常)提供支撑,而Framework2.0版中,公共语言运行库允许线程中的多数未处理异常自然继续。在多数情况下,这意味着未处理异常会导致应用程序终止。一、C/S解决方案(以下任何一种方法)1.在应用程序配置文件中,添加如下内容:configurationruntimelegacyUnhandledExceptionPolicyenabled=true//runtime/configuration2.在应用程序配置文件中,添加如下内容:configurationstartupsupportedRuntimeversion=v1.1.4322//startup/configuration3.使用Application.ThreadException事件在异常导致程序退出前截获异常。示例如下:[SecurityPermission(SecurityAction.Demand,Flags=SecurityPermissionFlag.ControlAppDomain)]publicstaticvoidMain(string[]args){Application.ThreadException+=newThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);AppDomain.CurrentDomain.UnhandledException+=newUnhandledExceptionEventHandler(CurrentDomain_UnhandledException);Application.Run(newErrorHandlerForm());}//在主线程中产生异常privatevoidbutton1_Click(objectsender,System.EventArgse){thrownewArgumentException(Theparameterwasinvalid);}//创建产生异常的线程privatevoidbutton2_Click(objectsender,System.EventArgse){ThreadStartnewThreadStart=newThreadStart(newThread_Execute);newThread=newThread(newThreadStart);newThread.Start();}//产生异常的方法voidnewThread_Execute(){thrownewException(Themethodoroperationisnotimplemented.);}privatestaticvoidForm1_UIThreadException(objectsender,ThreadExceptionEventArgst){DialogResultresult=DialogResult.Cancel;try{result=ShowThreadExceptionDialog(WindowsFormsError,t.Exception);}catch{try{MessageBox.Show(FatalWindowsFormsError,FatalWindowsFormsError,MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Stop);}finally{Application.Exit();}}if(result==DialogResult.Abort)Application.Exit();}//由于UnhandledException无法阻止应用程序终止,因而此示例只是在终止前将错误记录在应用程序事件日志中。privatestaticvoidCurrentDomain_UnhandledException(objectsender,UnhandledExceptionEventArgse){try{Exceptionex=(Exception)e.ExceptionObject;stringerrorMsg=Anapplicationerroroccurred.Pleasecontacttheadminstrator+withthefollowinginformation:/n/n;if(!EventLog.SourceExists(ThreadException)){EventLog.CreateEventSource(ThreadException,Application);}EventLogmyLog=newEventLog();myLog.Source=ThreadException;myLog.WriteEntry(errorMsg+ex.Message+/n/nStackTrace:/n+ex.StackTrace);}catch(Exceptionexc){try{MessageBox.Show(FatalNon-UIError,FatalNon-UIError.Couldnotwritetheerrortotheeventlog.Reason:+exc.Message,MessageBoxButtons.OK,MessageBoxIcon.Stop);}finally{Application.Exit();}}}privatestaticDialogResultShowThreadExceptionDialog(stringtitle,Exceptione){stringerrorMsg=Anapplicationerroroccurred.Pleasecontacttheadminstrator+withthefollowinginformation:/n/n;errorMsg=errorMsg+e.Message+/n/nStackTrace:/n+e.StackTrace;returnMessageBox.Show(errorMsg,title,MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Stop);}二、B/S解决方案(以下任何一种方法)1.在IE目录(C:/ProgramFiles/InternetExplorer)下建立iexplore.exe.config文件,内容如下:?xmlversion=1.0?configurationruntimelegacyUnhandledExceptionPolicyenabled=true//runtime/configuration2.不建议使用此方法,这将导致使用framework1.1以后版本的程序在IE中报错。建立同上的配置文件,但内容如下:?xmlversion=1.0?configurationstartupsupportedRuntimeversion=v1.1.4322//startup/configuration3.这个比较繁琐,分为三步:⑴.将下面的代码保存成文件,文件名为UnhandledExceptionModule.cs,路径是C:/ProgramFiles/MicrosoftVisualStudio8/VC/usingSystem;usingSystem.Diagnostics;usingSystem.Globalization;usingSystem.IO;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Threading;usingSystem.Web;namespaceWebMonitor{publicclassUnhandledExceptionModule:IHttpModule{staticint_unhandledExceptionCount=0;staticstring_sourceName=null;staticobject_initLock=newobject();staticbool_initialized=false;publicvoidInit(HttpApplicationapp){//DothisonetimeforeachAppDomain.if(!_initialized){lock(_initLock){if(!_initialized){stringwebenginePath=Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(),webengine.dll);if(!File.Exists(webenginePath)){thrownewException(String.Format(CultureInfo.InvariantCulture,Failedtolocatewebengine.dllat'{0}'.Thismodulerequires.NETFramework2.0.,webenginePath));}FileVersionInfover=FileVersionInfo.GetVersionInfo(webenginePath);_sourceName=string.Format(CultureInfo.InvariantCulture,ASP.NET{0}.{1}.{2}.0,ver.FileMajorPart,ver.FileMinorPart,ver.FileBuildPart);if(!EventLog.SourceExists(_sourceName)){thrownewException(String.Format(CultureInfo.InvariantCulture,ThereisnoEventLogsourcenamed'{0}'.Thismodulerequires.NETFramework2.0.,_sourceName));}AppDomain.CurrentDomain.UnhandledException+=newUnhandledExceptionEventHandler(OnUnhandledException);_initialized=true;}}}}publicvoidDispose(){}voidOnUnhandledException(objecto,UnhandledExceptionEventArgse){//LetthisoccuronetimeforeachAppDomain.if(Interlocked.Exchange(ref_unhandledExceptionCount,1)!=0)return;StringBuildermessage=newStringBuilder(/r/n/r/nUnhandledExceptionloggedbyUnhandledExceptionModule.dll:/r/n/r/nappId=);stringappId=(string)AppDomain.CurrentDomain.GetData(.appId);if(appId!=null){message.Append(appId);}ExceptioncurrentException=null;for(currentException=(Exception)e.ExceptionObject;currentException!=null;currentException=currentException.In

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功