首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用的目标引发了C#异常

问调用的目标引发了C#异常
EN

Stack Overflow用户
提问于 2016-06-17 13:23:19
回答 1查看 11.3K关注 0票数 1

在从IDE或exe运行我的C# .net 4.5 windows窗体项目时,我遇到了这个错误,我没有明确或固定的场景,在抛出的异常中找不到线索。我想知道如何获得错误的来源并修复它,或者至少以一种不会导致exe崩溃的方式来处理它!以下是例外情况的详细情况:

消息:

调用的目标引发了异常。

内部异常消息:

试图读取或写入受保护的内存。这通常表明其他内存已损坏。

内部异常堆栈跟踪:

在System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,IntPtr hWnd,Int32 msg,IntPtr wParam( System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m)在System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TextBoxBase.WndProc(Message& m( System.Windows.Forms.RichTextBox.WndProc(Message& m)在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m(System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd的.Control.ControlNativeWindow.WndProc(Message& m)( System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd的Int32 msg,IntPtr wparam,IntPtr lparam),System.Windows.Forms.RichTextBox.StreamIn(Stream数据的Int32 msg,Int32 wParam,EDITSTREAM lParam),Int32标志) (在System.Windows.Forms.RichTextBox.StreamIn(String时,System.Windows.Forms.RichTextBox.set_Rtf(String值处的Int32标志))在C:\TFS\TFS\Tragging\TraggingSolutions\TragTask\TragTask\UserControls\CommentControl.cs:line 76中的TragTask.UserControls.CommentControl.SetCommentInfo() ) 在C中的TragTask.UserControls.CommentControl.set_Comment(TaskMilestoneTimerAndComment值):\TFS\陷阱\陷阱Solutions\TragTask\TragTask\UserControls\CommentControl.cs:line 49 在C中的TragTask.Forms.frmTaskDetails.d__24.MoveNext():\TFS\Tragging\ Solutions\TragTask\TragTask\Forms\frmTaskDetails.cs:line 339 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object stateMachine)在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext),ContextCallback回调,对象状态,布尔preserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,Object状态,( System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run() at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClass11_0.b__0() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke() at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<>c.<.cctor>b__8_0(Object state)

TargetSite

{System.Object InvokeMethod(System.Object,System.Object[],System.Signature,布尔)}

目标站点,声明类型:

{Name = "RuntimeMethodHandle“FullName = "System.RuntimeMethodHandle"}

堆栈跟踪:

在System.RuntimeMethodHandle.InvokeMethod(Object目标,Object[]参数,签名sig,布尔构造函数( at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[]参数,Object[]参数) at System.Delegate.DynamicInvokeImpl(Object[] args) at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) ) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,Object state,( System.Threading.ExecutionContext.Run(ExecutionContext executionContext )、ContextCallback回调( ContextCallback回调)、对象状态( Object state )、布尔( Boolean )( System.Threading.ExecutionContext.Run(ExecutionContext executionContext )、ContextCallback回调(ContextCallback preserveSyncCtx)、对象状态( Object preserveSyncCtx) ( System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) ( System.Windows.Forms.Control.InvokeMarshaledCallbacks() ) ( System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam( System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) ) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32原因,Int32 pvLoopData在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文)在System.Windows.Forms.Application.Run() at TragTask.Program.Main()

Update在C.Evenhuis指出这与CommentControl.SetCommentInfo方法有关之后,我认为需要在我的问题中添加这个方法(注意,tb_comment是一个RichTextBox控件):

代码语言:javascript
复制
public bool SetCommentInfo()
{
    try
    {
        this.SuspendLayout();

        lbl_user.Text = "userName";
        lbl_dateTime.Text = mComment.DateTimeAdded.ToString("dd/MM/yyyy HH:mm:ss");

        if (mComment.Comment.TrimStart().StartsWith("{\\rtf1", StringComparison.Ordinal))
        {
            tb_comment.Clear();
            tb_comment.Text = "";
            tb_comment.Rtf = mComment.Comment;
        }
        else
            tb_comment.Text = mComment.Comment;

        return true;
    }
    catch (Exception ex)
    {
        Utils.Global.ErrorLog("SetCommentInfo", ex, true);
        return false;
    }
    finally
    {
        this.ResumeLayout();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-06-17 13:28:32

MSDN

已损坏的进程状态异常是表示进程状态已损坏的异常。不建议在这种状态下执行应用程序。

默认情况下,公共语言运行库(CLR)不会将这些异常传递给托管代码,并且不会为它们调用try/catch块(和其他异常处理子句)。如果您完全确定要维护对这些异常的处理,则必须将属性应用于要执行其异常处理子句的方法。CLR只在具有和SecurityCriticalAttribute属性的方法中将损坏的进程状态异常传递给适用的异常子句。

还可以将该文件添加到应用程序的配置文件中。这将确保在没有或SecurityCriticalAttribute属性的情况下将损坏的状态异常传递给异常处理程序。此配置元素对在.NET框架4之前版本编译但在.NET Framework4或更高版本中运行的应用程序没有影响;将继续为这些应用程序传递损坏的状态异常。当在部分受信任或透明的代码中遇到属性时,会忽略它,因为受信任的主机不应该允许不受信任的外接程序捕获和忽略这些严重的异常。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37882736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档