Exception thrown in SSCE 3.5 Beta2 but not in 3.5 beta1and early versions(来自MSDN Forum)

原文地址:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2001893&SiteID=1 I replace 
   I replace the reference assembly System.Data.SqlServerCe with version 3.5 beta2 in Microsoft.Practices.EnterpriseLibrary.Data.SqlCe. When I used the Data.SqlCe block in application, an exception ("Cannot access a disposed object named SqlCeConnection") threw. This didn't occur in SSCE 3.5 beta1 and early versions.

   Finally I found the difference between beta1 and beta2.

   In the SqlCeConnection class, there is a RemoveWeakReference method. this is code snippet of beta1:

internal void RemoveWeakReference(object value)

            {

            if (this.weakReferenceCache != null)

            {

            this.weakReferenceCache.Remove(value);

            }

            }

 and this is for beta2:




  
    
internal void RemoveWeakReference(object value)

            {

            if (this.weakReferenceCache == null)

            {

            throw new ObjectDisposedException("SqlCeConnection");

            }

            this.weakReferenceCache.Remove(value);

            }

            


So, if we dispose a connection before a command, such as:
SqlCeConnection cn;
SqlCeCommand cmd;
...
cn.Dispose();
cmd.Dispose(); // Error, an exception will be threw.
Is it a bug of Beta2?

=================================================
This is a issue in Beta2. Most probably we will fix in SSCE 3.5 RTM. The Bug Id: 13211 tracks this issue.

你可能感兴趣的:(exception)