ServiceEndpoint.Validate method throws null reference exception RRS feed

  • Question

  • Dear WCF developers,

    In our multi-threading application the instance of ServiceEndpoint class was shared among several threads in static variable and seemed to be constant.

    The issue was - we occasionally were getting null reference exception:

    <f:AppErr source="System.ServiceModel.Description.ServiceEndpoint.Validate">
    <f:ErrMessage>Object reference not set to an instance of an object.</f:ErrMessage>
    <f:Module name="System.ServiceModel.Description.ServiceEndpoint, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 ()" />

    Then we made it non-static and started recreating it for each remote call in each thread. Тhe exception fortunately disappeared after that change.

    Could someone explain what could be wrong in our application? Can ServiceEndpoint instance be shared and used simultaneously from several threads? Is it thread-safe?

    MSDN says, it is:

    Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

    Monday, November 2, 2015 7:16 PM