dotnet 2003/compact framework dataview find method invalidcastexception.. need explanation.

M

MCDONAMW

I am coding for pocket pc 2002. Strange error that took me a while to
recover from, but I don't understand why it works.

I have a Microsoft Access 2000 database exported into xml (data and
schema) via the dataset.writexml method. The xml is transfered to the
pocketpc and read in via readxml (schema first, and then data).

At some point I'm trying to find a particular value via setting up a
dataview on one of the tables, and setting the sort to the column I
want to index. I then use a textbox to enter my value I want to
search for, and then execute.

My code bombs with an invalidcastexception.

This is what the code was:
Dim i_location As Integer = 0
i_location = dv.Find(TextBox1.Text)

This works in vb.net 2003 perfectly fine. But on the compactframework
(v1.1), it throws the castexception.

At first I realized that my column is an integer, so I figure the
implicit conversion from string to integer is failing. (which does
not fail on the same code in a vb 2003 project). so I used
cint(textbox1.text) as my parameter for the find method. This failed
as well.

Through some manual debugging of my own, i realized that my xml schema
shows the column I'm searching is of datatype int16. An integer is
int32 in .NET, which is what i_location is. dv.find is supposed to
return an integer (int32) of the record I am looking for. The MSDN
documentation does not specify what valid parameters are for the
dv.find method. All examples use strings. This led me to believe it
would implicitly convert the string to whatever to search the dv. I
guess I was wrong? (but only in compactframework?)

To reiterate my findings, the bombing is coming from the actual FIND
method itself. Why?!?! I have to use cshort(textbox1.text) as my
parameter in order for the CompactFramework to work correctly. (again
vb.net has no problems with just cint(textbox1.text) or even just
textbox1.text for that matter.

Why is this?? Having to rely on changing this to cshort limits the
values I'm using for my text box because if the number is large enough
the cshort conversion fails hard. (obviously I should be coding
around this as good development would call for. I know I shouldn't be
relying on implicit conversions, but I want to know why it's even
happening!). What is different about the compactframework and the
regular framework in that the dataview find method will not process
the find unless the parameter matches the column value in type
explicitly? Is the dv.find method is supposed to take an OBJECT, so
it shouldn't matter what I pass it, correct? Apparently the CF
doesn't like this notion.

Second question is why does MS access see an integer as 2 bytes, but
..NET sees it as 4 bytes?? Shouldn't the machine itself define how big
an integer is? Or how big the word sizes are, etc?
 
I

Ilya Tumanov [MS]

The first one is easy to explain: it's a bug in a Compact Framework which
would cause InvalidCastException in Find() in case argument type(s) and
sort key type(s) are mismatched.
You've found the workaround already - cast the find argument to the key
type. That's in fact a good idea from performance point of view as well.
This bug has been fixed in SP2, as far as I remember. You can install SP2
to fix that problem.

As to your second question, "Integer" could mean pretty much anything, it
depends on specific language running on specific platform.

In VB.Net "Integer" is 32 bit signed value, alias of System.Int32.
That might not be the case with other languages/databases even running on
the same computer.
Here's some quote from MSDN:

"Caution If you are interfacing with components written in Visual Basic
version 6.0, for example Automation or COM objects, keep in mind that
Integer has a different data width (16 bits) in Visual Basic 6.0. If you
are passing a 16-bit argument to such a component, declare it as Short
instead of Integer in Visual Basic .NET."

Best regards,

Ilya

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

--------------------
From: (e-mail address removed) (MCDONAMW)
Newsgroups: microsoft.public.dotnet.framework.compactframework
Subject: dotnet 2003/compact framework dataview find method
invalidcastexception.. need explanation.
 
M

MCDONAMW

Thank you for your response. It is much appreciated!.

You know I see people all over the place blaming problems on the
framework and sp2 being the fix, but honestly I believe I do have sp2.
My .NET is always up to date, as is my computer. I have the framework
sp2 windows update installed.. that's what they are referring to
correct? Or am I missing something altogether?

I would assume that my dev environment sp2 should be deployed onto the
pocketpc during a build/deployment correct? Am I wrong in this
assumption? (I distinctly remember during compiling that it pushed the
framework to the ipaq the first time before pushing the project itself.
It does this in the emulator too).

Is this a documented bug?

Remove underscores and nospam to email me.
 
I

Ilya Tumanov [MS]

No, I'm referring to the Compact Framework SP2 which is a separate entity.
You do not have it unless you downloaded it separately and installed on to
your device.

You can download it here:
http://www.microsoft.com/downloads/details.aspx?familyid=359ea6da-fc5d-41cc-
ac04-7bb50a134556&displaylang=en

Note: it would update runtime on device only, VS will continue to use RTM
version of CF.
You are correct, VS would deploy CF on to the device, but that would be RTM
version.
If you have CF SP2 installed on the device, VS won't deploy CF as it would
detect a newer version.
VS Service pack which would contain CF SP3 is expected soon.

This is a known (and fixed) bug, but I don't believe there's a KB article
for it. Here's the first report of it:

http://groups.google.com/groups?q=InvalidCastException+group:microsoft.publi
c.dotnet.framework.compactframework&hl=en&lr=&ie=UTF-8&group=microsoft.publi
c.dotnet.framework.compactframework&selm=wSjS9.9169%244k6.903414%40wards&rnu
m=8

Best regards,

Ilya

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

--------------------
From: MCDONAMW <[email protected]>
References: <[email protected]>
X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
Subject: RE: dotnet 2003/compact framework dataview find method
invalidcastexception.. need explanation.
 
M

MCDONAMW

You both rock. Thank you for all your help and guidance!

Remove underscores and nospam to email me.
 
M

MCDONAMW

Thank you again. Actually I have one more question. (i posted before
this, but it's around the same time so I don't know which will post
first).

I have installed the sp2 framework on the ipaq. You mentioned the
desktop will continue to use the rtm version? If that's the case, what
does the emulator use? I do alot of my work with the emulator. That
bombs as well due to the wrong framework.

Is there a way to install programs (i.e. this update) to the emulator?

Remove underscores and nospam to email me.
 
M

MCDONAMW

Wow that was quick. Cool. Believe it or not I found a way to do it via
more newsgroup searching.

I'm not too fond of adding this thing to my project and deploying it as
content, then manually running it, but I guess I have no choice.

Thanks for all your help!

Remove underscores and nospam to email me.
 

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