1

I have a Windows Forms application (.NET 3.5) which is deployed with the ClickOnce-technology and is used by approximately 50-100 concurrent users. They all target the same MS SQL database (SQL SERVER 2008 R2) which is hosted externally.

The application itself uses a "wrapper"-class to perform database queries. This class derives from ServicedComponent and decorates its methods with the [AutoComplete] attribute. Below is an example:

[Serializable]
[Transaction(TransactionOption.Required, Isolation=TransactionIsolationLevel.ReadCommitted)]
public class CTxGreenfee374Processor: ServicedComponent
{
    public CTxGreenfee374Processor() { }

    [AutoComplete]
    internal Season SaveSeason(CallContext callContext, Season season)
    {
        return new PGreenfee374Processor().SaveSeason(callContext, season);
    }
}

Most of the time this approach works like a charm. But numerous times a day following exception occur when this method gets invoked (of course there are similar methods with this exact problem):

System.ArgumentNullException
Value cannot be null.
Server stack trace: 
  at System.Threading.Monitor.Enter(Object obj) 
  at System.Data.ProviderBase.DbConnectionPool.TransactedConnectionPool.TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject) 
  at System.Data.ProviderBase.DbConnectionPool.TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject) 
  at System.Data.ProviderBase.DbConnectionInternal.CleanupConnectionOnTransactionCompletion(Transaction transaction) 
  at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment) 
  at System.Transactions.TransactionStateDelegatedCommitting.EnterState(InternalTransaction tx) 
  at System.Transactions.TransactionStateDelegated.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState) 
  at System.Transactions.CommittableTransaction.Commit() 
  at System.EnterpriseServices.TransactionProxy.Commit(Guid guid) 
  at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) 
  at System.EnterpriseServices.Thunk.Callback.DoCallback(Object otp, IMessage msg, IntPtr ctx, Boolean fIsAutoDone, MemberInfo mb, Boolean bHasGit) 
  at System.EnterpriseServices.ServicedComponentProxy.CrossCtxInvoke(IMessage reqMsg) 
  at System.EnterpriseServices.ServicedComponentProxy.Invoke(IMessage request) 
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
  at GOLFIT.BusinessProcess.Economics.CTxGreenfee374Processor.SaveSeason(CallContext callContext, Season season) 
  at GOLFIT.BusinessProcess.Economics.Greenfee374Processor.SaveSeason(CallContext callContext, Season season) in C:\Projekt\GOLFIT\DEVELOPMENTPROD374\BusinessProcess\GOLFIT.BusinessProcess.Economics\Greenfee374\Greenfee374Processor.cs:line 104 
  at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) 
  at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) 
  at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext) 
Exception rethrown at [0]: 
  at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
  at GOLFIT.BusinessProcess.Economics.Greenfee374Processor.SaveSeason(CallContext callContext, Season season)
  at GOLFIT.WinGUI.Economics.FrmPrice374.Save(Boolean refresh). 

As you can see the method SaveSeason in the CTxGreenfee374Processor class is mentioned in the exception. As far as I can see this is the last trace of code that I've written.

My only clue is that the exception has something to do with the [AutoComplete] attribute and/or the derived ServicedComponent class. This conclusion is based on that I've checked for invalid input parameters and that no code inside the method gets executed before the exception. And I assume that both ServicedComponent class and [AutoComplete] attribute performs som kind of logic before the method block executes.

I haven't been successful in recreating this exception when debugging, due to inconsequent occurrences of this exeption. So I've had to depend on logs from the production application.

If anyone got an idea regarding this problem it would be extremely appreciated!

  • Is there any threading involved ? – Heslacher Sep 04 '13 at 09:33
  • No, the method is invoked on the main thread when the user clicks a button in a Windows Form. And there isn't an other threads alive in the meantime. – Danny Skoog Sep 04 '13 at 10:14
  • Can you edit your post to show the checking for invalid input ? – Heslacher Sep 04 '13 at 10:16
  • There aren't any actual validation of the input parameters for the method above. I meant that I've manually tested the method by applying null values for each of the input parameters. But in that case the exception specifies the "Parameter name: XXX". So I'm sure that's not the issue. It seems to me, by looking at the stacktrace, that the parameter "obj" for the Monitor.Enter-method is the case of the argumentnullexception. – Danny Skoog Sep 04 '13 at 10:43
  • Check if this answer will help you [http://stackoverflow.com/a/13488009/2655508](http://stackoverflow.com/a/13488009/2655508) – Heslacher Sep 04 '13 at 10:57
  • Yeah. I saw that solution earlier, but didn't think it applied to me. But now that I've investigated it a little bit deeper i found that my production server indeed has the "2.50727.4016" version of the "System.Data.dll", which is mentioned in the answer. And as my application runs on .NET 3.5 i assume it uses the .NET 2-version of the "System.Data.dll". So I'm going to try an get the mentioned hotfix from microsoft and check if that fixes the problem. Unless you have any other thoughts or suggestions? Thanks for being so helpful this far, btw. – Danny Skoog Sep 04 '13 at 12:44
  • No other thoughts here ;-( – Heslacher Sep 04 '13 at 12:52
  • Installation of the hotfix mentioned in the link provided by @Heslacher solved the problem. Thanks! – Danny Skoog Jan 07 '14 at 09:58

0 Answers0