开发者

Null reference exception while Invoke on a WCF triggered event connected method

Please help me out. I am stuck at one situation with WCF. I am working on an client-server app, where server exposes its services through a WCF Duplex channel. The whole mechanism is built as a Pub-Sub pattern. Server executes a remote method in every client proxy connected to it and sends an updated entity as an argument. Client proxy raises an event called UpdateEntityEvent. Every client module is subscribed to this event with a method called UpdateData(Entity ent) through which every part of the program gets new or updated objects. I never had such problems until now that I received such an exception in one of the modules, to be more specific situation is not repeatable by every client. One day it occurred on one client station for a specific user, who (if it is meaningful) has a laptop with i3 processor, when other clients work on "weaker" machines. This is the error:

<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 obj开发者_如何学JAVAect.
       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>

The UpdateData() method is like this:

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
        }
    }

Additional info is, that the entity object that the control receives through UpdateData provides some data that is used to fill a commercial Spreadsheet control. My question is: what causes this error, a NULL in the Entity object passed in UpdateData or is it an Invoke problem. If so, how does it happen that it has a NULL reference in Invoke when UpdateData is subscribed to Update event earlier and would never have a chance to be triggered otherwise than through subscribe procedure which is called in control's constructor long after InitializeComponent ?? What is NULL here, if this was sth. inside the Entity object, wouldn't the error have been more specific??

Thank you for any ideas

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜