System.ComponentModel.Component and IDisposable

G

gonzalez

I have code I need to share between the regular framework and the .Net CF,
and I'm wondering what the reason is for .Net CF Component class not
implementing IDisposable? Currently my code relies on IDisposable, and I
have to convert the code to call Dispose() on the class instead. This
breaks IDisposable interface polimorphism, and the using() construct as
well. Is there something I need to be aware of on resource management for
the Compact Framework?

Note:
Just looking for a logical explanation to all the code rewriting I have to
do, not to mention the loss of interface based polimorphism and broken using
statement.

Thanks in Advance,
--Ader.
 
G

gonzalez

Thank you Ilia,

While we're on bugs (you may already know about this other one), when using
Sql Ce, I've noticed that the Exception message shows up as blank, and only
when I cast the Exception I can get the message, i.e.:

// in this sample x is a SqlCeException that got thrown

try {
....
}
catch (Exception x) {
Debug.WriteLine(x.Message); // <-- blank message value
Debug.WriteLine((x as SqlCeException).Message); // <-- now I get the
message value
}

This funny behavior affects more than just SqlCeException and it makes
debugging harder.

Thanks,
--Ader.
 
I

Ilya Tumanov [MS]

Some exceptions in NETCF don't have messages at all, even in NETCF V2 for
which number of messages greatly increased.

I know it's frustrating and I'm sorry about that.



Fortunately, that's not the case with SQL CE and Client exceptions; they
have error collections with detailed error messages.

SqlCeException description on MSDN has sample on how to print them out.


Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
D

Darren Shaffer

private void _displaySQLCEErrors(SqlCeException ex)
{
SqlCeErrorCollection errorCollection = ex.Errors;

StringBuilder bld = new StringBuilder();
Exception inner = ex.InnerException;

foreach (SqlCeError err in errorCollection)
{
bld.Append("\n Error Code: " + err.HResult.ToString("X"));
bld.Append("\n Message : " + err.Message);
bld.Append("\n Minor Err.: " + err.NativeError);
bld.Append("\n Source : " + err.Source);

foreach (int numPar in err.NumericErrorParameters)
{
if ( 0 != numPar ) bld.Append( "\n Num. Par. : " + numPar );
}

foreach ( string errPar in err.ErrorParameters )
{
if ( String.Empty != errPar ) bld.Append( "\n Err. Par. : " + errPar );
}

MessageBox.Show( bld.ToString(), "SQL Server CE Error" );
bld.Remove(0, bld.Length);
}
}

--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 
G

gonzalez

Thank you for your responses... However I was referring to a more generic
problem with properties that seems
to affect a lot of the Compact framework. For example, in the the
following case which works for the regular framework, I'm adding subitems to
a ListView.. and I'm using the last subitem (3) for the ModelID, however it
doesn't get displayed. On the regular framework I can pull the value from
the ListViewSubItem[3].Text property... On the CF I get blank ("").

Here's the Immediate window result:

((ListViewItem.ListViewSubItem)lvModels.Items[1].SubItems[3])
{System.Windows.Forms.ListViewItem.ListViewSubItem}

System.Object: {System.Windows.Forms.ListViewItem.ListViewSubItem}

m_fParented: true

m_iSubItem: 3

m_lvi: {Text="2003"}

m_Text: "0820030440"

Parent: {Text="2003"}

Text: ""


Notice taht m_Text has a value, but Text retuns "".

Here's how I add the ListView Items:
this.lvModels.Items.Clear();

this.lblMake.Text = modelList[0].Make;

foreach(Model m in modelList) {

ListViewItem i = new ListViewItem();

i.Text = Convert.ToString(m.Year);

i.SubItems.Add(m.ModelName);

i.SubItems.Add(m.BodyStyle);

i.SubItems.Add(m.ModelID); //Value: 0820030440 goes in

lvModels.Items.Add(i);

}


Thanks again for all your help.
--Ader.
 
G

gonzalez

Thank you for response Ilya, I understand that some don't have messages but
in this case there seems to be
a misbehaviour with properties (as if the property wasn't polimophic), and
when the exception is re-casted to it's
actual type then the value gets pulled out correctly.

This problem seems to affect other parts of the framework too (see my other
message to Darren Shaffer).

Thanks,
--Ader.

PS.
I can't wait to move to .Net CF 2.0, maybe some of these issues have been
fixed... However my current requirements
got me stuck with VS 2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top