Bug in .NET CF 2.0 ??

K

Kim Würtz

Hi All

I have noticed what appears to be a bug during migration of a C# project
from .NET 1.0 to .NET 2.0.

I have an application running on a Windows Mobile 2003 SE developed with VS
2003 using .NET CF 1.0 with no problems what so ever.

However recently I had to upgrade to VS 2005 and during the first load of
the C# project I was asked to upgrade the project to .NET CF 2.0, hich I
accepted. I was able to recompile the project in VS 2005 with no errors.
HOWEVER when I deployed and ran the application I consistently got an
exception:

NotSupportedException

No difference if I run it on a real device or on the emulator.

A snippet of the code (simplified for clarity) goes like this:

private void SomeWork()

{

TEST info;

info = new TEST(Marshal.SizeOf(typeof(TEST))); ********* The
NotSupportedException is thrown here

}



public class TEST : Struct

{

public int some_data;

public TEST(int size) : base(size)

{

}

}

public class Struct

{

byte[] i_data;

public Struct(int size)

{

i_data = new byte[size];

}

}

What am I missing ??

Best regrads and thanks in advance

Kim Würtz
 
I

Ilya Tumanov [MS]

If you run that on desktop, I suspect you would get an exception saying
something like this: No meaningful size can be determined for none blittable
type.

That's why it's not working for you. I suspect NETCF V1 is not as strict and
would give you size, but it would be just meaningless number.

You can fix that by using correct MarshalAs attributes as needed. You can
also replace array with IntPtr and add code to set up pointer to this array.


--
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).
 
K

Kim Würtz

Thanks for your reply Ilya

I am new in using marshalling i .NET. Could you
extend my code snippet using this MarshalAs so
I can pick up the idea ?

Best regards

Kim Würtz

Ilya Tumanov said:
If you run that on desktop, I suspect you would get an exception saying
something like this: No meaningful size can be determined for none
blittable type.

That's why it's not working for you. I suspect NETCF V1 is not as strict
and would give you size, but it would be just meaningless number.

You can fix that by using correct MarshalAs attributes as needed. You can
also replace array with IntPtr and add code to set up pointer to this
array.


--
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).

Kim Würtz said:
Hi All

I have noticed what appears to be a bug during migration of a C# project
from .NET 1.0 to .NET 2.0.

I have an application running on a Windows Mobile 2003 SE developed with
VS 2003 using .NET CF 1.0 with no problems what so ever.

However recently I had to upgrade to VS 2005 and during the first load of
the C# project I was asked to upgrade the project to .NET CF 2.0, hich I
accepted. I was able to recompile the project in VS 2005 with no errors.
HOWEVER when I deployed and ran the application I consistently got an
exception:

NotSupportedException

No difference if I run it on a real device or on the emulator.

A snippet of the code (simplified for clarity) goes like this:

private void SomeWork()

{

TEST info;

info = new TEST(Marshal.SizeOf(typeof(TEST))); ********* The
NotSupportedException is thrown here

}



public class TEST : Struct

{

public int some_data;

public TEST(int size) : base(size)

{

}

}

public class Struct

{

byte[] i_data;

public Struct(int size)

{

i_data = new byte[size];

}

}

What am I missing ??

Best regrads and thanks in advance

Kim Würtz
 
I

Ilya Tumanov [MS]

I can not extend your code as I don't know what it supposed to do.

MSDN has code snippets for MarshalAs, please look it up and use as
appropriate in your case.



Also please see this:



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfintrointerp.asp

http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfadvinterop.asp



--
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).

Kim Würtz said:
Thanks for your reply Ilya

I am new in using marshalling i .NET. Could you
extend my code snippet using this MarshalAs so
I can pick up the idea ?

Best regards

Kim Würtz

Ilya Tumanov said:
If you run that on desktop, I suspect you would get an exception saying
something like this: No meaningful size can be determined for none
blittable type.

That's why it's not working for you. I suspect NETCF V1 is not as strict
and would give you size, but it would be just meaningless number.

You can fix that by using correct MarshalAs attributes as needed. You can
also replace array with IntPtr and add code to set up pointer to this
array.


--
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).

Kim Würtz said:
Hi All

I have noticed what appears to be a bug during migration of a C# project
from .NET 1.0 to .NET 2.0.

I have an application running on a Windows Mobile 2003 SE developed with
VS 2003 using .NET CF 1.0 with no problems what so ever.

However recently I had to upgrade to VS 2005 and during the first load
of the C# project I was asked to upgrade the project to .NET CF 2.0,
hich I accepted. I was able to recompile the project in VS 2005 with no
errors. HOWEVER when I deployed and ran the application I consistently
got an exception:

NotSupportedException

No difference if I run it on a real device or on the emulator.

A snippet of the code (simplified for clarity) goes like this:

private void SomeWork()

{

TEST info;

info = new TEST(Marshal.SizeOf(typeof(TEST))); ********* The
NotSupportedException is thrown here

}



public class TEST : Struct

{

public int some_data;

public TEST(int size) : base(size)

{

}

}

public class Struct

{

byte[] i_data;

public Struct(int size)

{

i_data = new byte[size];

}

}

What am I missing ??

Best regrads and thanks in advance

Kim Würtz
 
K

Kim Würtz

Hi

I have been trying to puzzling around with the MarshalAs with no succes,
that is
I am still receiving the NotSupportedException no matter how I marshall the
data
in the base class (byte []).

As I wrote, the app. works with CF 1.0. Hence I have been debugging the app.
based on the CF 1.0 to figure out what the correct return value of the
Marshal.Sizeof
is.

In the example below the TEST class contains one variable named int
some_data occupying
4 bytes as an unmanaged type and that is exactly what marshal.sizeof returns
IF the TEST
class DO NOT inherit from the Struct class. However when inheriting from the
base class
as suggested below, 8 is returned from marshal.sizeof. If I declare
additional int variables in
the TEST class, the return value from marshal.sizeof increases by 4 for each
int declared as
expected.

Thus this formula can be setup

return value from Marshal.Sizeof = (# of int data declared in TEST class) *
4 + 4.


Trying to do same with CF 2.0 throw the exception if and only if the TEST
class inherits
from the base class (Struct class).

How can that be ?

I have not written all the app my self so I am not fully aware of the
implementation but
the app contains several different data structures defined in classes. All
these data structures
contains purely ints and are passed to/from unmanaged code. But before that
can take place, some
common manipulation with these data has to be done, which is carried out by
the base class.

Hope some can help me solve this annoying problem.

Best regeards
Kim Würtz





Ilya Tumanov said:
I can not extend your code as I don't know what it supposed to do.

MSDN has code snippets for MarshalAs, please look it up and use as
appropriate in your case.



Also please see this:



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfintrointerp.asp

http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfadvinterop.asp



--
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).

Kim Würtz said:
Thanks for your reply Ilya

I am new in using marshalling i .NET. Could you
extend my code snippet using this MarshalAs so
I can pick up the idea ?

Best regards

Kim Würtz

Ilya Tumanov said:
If you run that on desktop, I suspect you would get an exception saying
something like this: No meaningful size can be determined for none
blittable type.

That's why it's not working for you. I suspect NETCF V1 is not as strict
and would give you size, but it would be just meaningless number.

You can fix that by using correct MarshalAs attributes as needed. You
can also replace array with IntPtr and add code to set up pointer to
this array.


--
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).

Hi All

I have noticed what appears to be a bug during migration of a C#
project from .NET 1.0 to .NET 2.0.

I have an application running on a Windows Mobile 2003 SE developed
with VS 2003 using .NET CF 1.0 with no problems what so ever.

However recently I had to upgrade to VS 2005 and during the first load
of the C# project I was asked to upgrade the project to .NET CF 2.0,
hich I accepted. I was able to recompile the project in VS 2005 with no
errors. HOWEVER when I deployed and ran the application I consistently
got an exception:

NotSupportedException

No difference if I run it on a real device or on the emulator.

A snippet of the code (simplified for clarity) goes like this:

private void SomeWork()

{

TEST info;

info = new TEST(Marshal.SizeOf(typeof(TEST))); ********* The
NotSupportedException is thrown here

}



public class TEST : Struct

{

public int some_data;

public TEST(int size) : base(size)

{

}

}

public class Struct

{

byte[] i_data;

public Struct(int size)

{

i_data = new byte[size];

}

}

What am I missing ??

Best regrads and thanks in advance

Kim Würtz
 

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