在WCF触发事件连接方法上调用时出现空引用异常

时间:2010-12-02 13:07:36

标签: c# wcf event-handling nullreferenceexception

请帮帮我。我遇到了WCF的一种情况。我正在开发一个客户端 - 服务器应用程序,其中服务器通过WCF双工通道公开其服务。整个机制构建为Pub-Sub模式。服务器在连接到它的每个客户端代理中执行远程方法,并将更新的实体作为参数发送。客户端代理引发一个名为UpdateEntityEvent的事件。每个客户端模块都使用一个名为UpdateData(Entity ent)的方法订阅此事件,程序的每个部分都通过该方法获取新的或更新的对象。我从来没有遇到过这样的问题,直到现在我在其中一个模块中收到了这样的例外,更具体的情况是每个客户都无法重复。有一天,它出现在一个特定用户的客户工作站上,当有其他客户工作“较弱”的机器时,他们(如果有意义的话)有一台带有i3处理器的笔记本电脑。这是错误:

<log4j:event logger="Client Application" timestamp="1291132669957" level="INFO" thread="WCF Layer"><log4j:message>User has started application and logged in with success.</log4j:message>
    <log4j:event logger="Client Application" timestamp="1291133884092" level="FATAL" thread="11"><log4j:message>Type: 
    Source: 
    System.Windows.Forms
    Method: 
    System.Object MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean)
    Mesage: 
    Object reference not set to instance of an object.
    StackTrace: 
       w System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       w System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       w ClientApplication.Controls.RampDashboard.MyTasksControl.UpdateData(Entity entity)
       w ClientDataProvider.DataProvider.UpdateEntityHandler.Invoke(Entity value)
       w ClientDataProvider.DataProvider.UpdateEntityThread(Object obj) w C:\SomeDir\SomeFile.cs:row 380
       w System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
       w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       w System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
       w System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
    InnerException: 

    <log4j:throwable>System.NullReferenceException: Object reference not set to instance of an object.
       w System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       w System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       w ClientApplication.Controls.RampDashboard.MyTasksControl.UpdateData(Entity entity)
       w ClientDataProvider.DataProvider.UpdateEntityHandler.Invoke(Entity value)
       w ClientDataProvider.DataProvider.UpdateEntityThread(Object obj) w C:\SomeDir\SomeFile.cs:row 380
       w System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
       w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       w System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
       w System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)</log4j:throwable><log4j:locationInfo class="ClientApplication.Program" method="CurrentDomainUnhandledException" file="" line="0" /></log4j:event>

UpdateData()方法如下:

private delegate void UpdateDataHandleDelegate(Entity entity);
    /// <summary>
    /// Updates the data.
    /// </summary>
    /// <param name="entity">The entity.</param>
    private void UpdateData(Entity entity)
    {
        if (InvokeRequired)
        {
            Invoke(new UpdateDataHandleDelegate(UpdateData), entity);
        }
        else
        {
               // business logic here
        }
    }

附加信息是,控件通过UpdateData接收的实体对象提供了一些用于填充商业电子表格控件的数据。我的问题是:导致此错误的原因是,在UpdateData中传递的Entity对象中是NULL还是Invoke问题。如果是这样,当UpdateData先前订阅了Update事件时,如果它在Invoke中有一个NULL引用,并且除了通过在InitializeComponent之后很长时间内在控件的构造函数中调用的subscribe过程,它将永远不会被触发。什么是NULL,如果这是......在Entity对象里面,错误是不是更具体?

感谢您提出任何想法

0 个答案:

没有答案
相关问题