System.Data.SQLite
View Ticket
Not logged in
Ticket UUID: badfb178a622e42a03743d1a7b7d0ea410115074
Title: Managed Debugging Assistant 'ReleaseHandleFailed'
Status: Closed Type: Code_Defect
Severity: Important Priority: Low
Subsystem: Integration_Via_PInvoke Resolution: External_Bug
Last Modified: 2011-10-11 05:04:22
Version Found In: 1.0.72
Description:
This behavior also exists in 1.0.66

When running my code under VS2010 with all managed debugging assistants on the exception window switched on I get 4 instances of the following:

Managed Debugging Assistant 'ReleaseHandleFailed' has detected a problem in 'C:\projects\_Demo.exe'. Additional Information: A SafeHandle or CriticalHandle of type 'Microsoft.Win32.SafeHandles.SafeCapiHashHandle' failed to properly release the handle with value 0x0049C110. This usually indicates that the handle was released incorrectly via another means (such as extracting the handle using DangerousGetHandle and closing it directly or building another SafeHandle around it.)

This happens at the first garbage collection after I've connected to my data source and fetched some data.


shane added on 2011-05-28 12:31:41 UTC:
Can you please provide a code example that demonstrates this? Thanks.


anonymous added on 2011-06-08 13:04:31 UTC:
I don't do anything special. If you want to contact me directly, please use s q l i t e (at) w i e s e r - s o f t w a r e . c o m

I created my entity data model, and connect thus:

string connection = string.Format("metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SQLite;provider connection string='data source=\"{0}\"'", PayrollDBFilename); try { _dbPAYE = new PAYEDatabase(connection); var Employers = (from employer_data er in _dbPAYE.employer_data select er).ToList(); GC.Collect(); GC.WaitForPendingFinalizers(); // the managed debugging exception is thrown // before hitting the next statement bSucceeded = true; }

The PAYEDatabase constructor being used contains this: /// <summary> /// Initialize a new PAYEDatabase object. /// </summary> public PAYEDatabase(string connectionString) : base(connectionString, "PAYEDatabase") { this.ContextOptions.LazyLoadingEnabled = true; OnContextCreated(); }

employer_data is defined like this: /// <summary> /// No Metadata Documentation available. /// </summary> public ObjectSet<employer_data> employer_data { get { if ((_employer_data == null)) { _employer_data = base.CreateObjectSet<employer_data>("employer_data"); } return _employer_data; } } private ObjectSet<employer_data> _employer_data;

employer_data is just the data model generated class (awfully big, at end of message).

REMEMBER: No error is shown unless you have gone to Debug | Exceptions and switched on all ManagedDebugExceptions. It seems to me that the problem must be something to do with the way Hash is used in the sqlite3.c file, as that's the only time that type of object appears to be used. My database has no password.
[EdmEntityTypeAttribute(NamespaceName="PayeMODEL", Name="employer_data")] [Serializable()] [DataContractAttribute(IsReference=true)] public partial class employer_data : EntityObject { #region Factory Method
/// <summary> /// Create a new employer_data object. /// </summary> /// <param name="edid">Initial value of the edid property.</param> /// <param name="erid">Initial value of the erid property.</param> public static employer_data Createemployer_data(global::System.Int64 edid, global::System.Int64 erid) { employer_data employer_data = new employer_data(); employer_data.edid = edid; employer_data.erid = erid; return employer_data; }
#endregion #region Primitive Properties
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribute()] public global::System.Int64 edid { get { return _edid; } set { if (_edid != value) { OnedidChanging(value); ReportPropertyChanging("edid"); _edid = StructuralObject.SetValidValue(value); ReportPropertyChanged("edid"); OnedidChanged(); } } } private global::System.Int64 _edid; partial void OnedidChanging(global::System.Int64 value); partial void OnedidChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)] [DataMemberAttribute()] public global::System.Int64 erid { get { return _erid; } set { if (_erid != value) { OneridChanging(value); ReportPropertyChanging("erid"); _erid = StructuralObject.SetValidValue(value); ReportPropertyChanged("erid"); OneridChanged(); } } } private global::System.Int64 _erid; partial void OneridChanging(global::System.Int64 value); partial void OneridChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String name { get { return _name; } set { OnnameChanging(value); ReportPropertyChanging("name"); _name = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("name"); OnnameChanged(); } } private global::System.String _name; partial void OnnameChanging(global::System.String value); partial void OnnameChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String address1 { get { return _address1; } set { Onaddress1Changing(value); ReportPropertyChanging("address1"); _address1 = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("address1"); Onaddress1Changed(); } } private global::System.String _address1; partial void Onaddress1Changing(global::System.String value); partial void Onaddress1Changed();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String address2 { get { return _address2; } set { Onaddress2Changing(value); ReportPropertyChanging("address2"); _address2 = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("address2"); Onaddress2Changed(); } } private global::System.String _address2; partial void Onaddress2Changing(global::System.String value); partial void Onaddress2Changed();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String address3 { get { return _address3; } set { Onaddress3Changing(value); ReportPropertyChanging("address3"); _address3 = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("address3"); Onaddress3Changed(); } } private global::System.String _address3; partial void Onaddress3Changing(global::System.String value); partial void Onaddress3Changed();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String postcode { get { return _postcode; } set { OnpostcodeChanging(value); ReportPropertyChanging("postcode"); _postcode = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("postcode"); OnpostcodeChanged(); } } private global::System.String _postcode; partial void OnpostcodeChanging(global::System.String value); partial void OnpostcodeChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String payeref { get { return _payeref; } set { OnpayerefChanging(value); ReportPropertyChanging("payeref"); _payeref = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("payeref"); OnpayerefChanged(); } } private global::System.String _payeref; partial void OnpayerefChanging(global::System.String value); partial void OnpayerefChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String accountsofficeref { get { return _accountsofficeref; } set { OnaccountsofficerefChanging(value); ReportPropertyChanging("accountsofficeref"); _accountsofficeref = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("accountsofficeref"); OnaccountsofficerefChanged(); } } private global::System.String _accountsofficeref; partial void OnaccountsofficerefChanging(global::System.String value); partial void OnaccountsofficerefChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String taxofficeref { get { return _taxofficeref; } set { OntaxofficerefChanging(value); ReportPropertyChanging("taxofficeref"); _taxofficeref = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("taxofficeref"); OntaxofficerefChanged(); } } private global::System.String _taxofficeref; partial void OntaxofficerefChanging(global::System.String value); partial void OntaxofficerefChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String taxofficenumber { get { return _taxofficenumber; } set { OntaxofficenumberChanging(value); ReportPropertyChanging("taxofficenumber"); _taxofficenumber = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("taxofficenumber"); OntaxofficenumberChanged(); } } private global::System.String _taxofficenumber; partial void OntaxofficenumberChanging(global::System.String value); partial void OntaxofficenumberChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public global::System.String econ { get { return _econ; } set { OneconChanging(value); ReportPropertyChanging("econ"); _econ = StructuralObject.SetValidValue(value, true); ReportPropertyChanged("econ"); OneconChanged(); } } private global::System.String _econ; partial void OneconChanging(global::System.String value); partial void OneconChanged();
/// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable<global::System.Int64> taxyear { get { return _taxyear; } set { OntaxyearChanging(value); ReportPropertyChanging("taxyear"); _taxyear = StructuralObject.SetValidValue(value); ReportPropertyChanged("taxyear"); OntaxyearChanged(); } } private Nullable<global::System.Int64> _taxyear; partial void OntaxyearChanging(Nullable<global::System.Int64> value); partial void OntaxyearChanged();
#endregion
}

mistachkin added on 2011-07-05 07:00:21 UTC:
I suspect the issue is not related to System.Data.SQLite, see:

StackOverflow question

According to MSDN, this MDA issue can only be caused by using (and failing to release) an object derived from SafeHandle or CriticalHandle. As far as I can see, neither type of handle is used by System.Data.SQLite.


mistachkin added on 2011-07-05 07:19:08 UTC:
Please disregard the previous comment, I found where System.Data.SQLite uses CriticalHandle objects. In "System.Data.SQLite\UnsafeNativeMethods.cs", both the SQLiteConnectionHandle and SQLiteStatementHandle derive from CriticalHandle.


mistachkin added on 2011-07-09 23:56:46 UTC:
The SafeCapiHashHandle type is not used by System.Data.SQLite. Per the StackOverflow link above, the MDA you are seeing is probably related to some other component in your process using SSL sockets for a web service or something similar.