Strongly typed datasets and .NET CF = System.TypeLoadException?

J

Joakim Englund

Hi all!

Is it possible to use strongly typed datasets in .NET CF.

I'm calling a web service from a smart device application running on P PC
2002 that returns a strongly typed dataset. Immediately when the call is
made I get a System.TypeLoadException. If I run the same application on
Windows XP I don't get any exception and the strongly typed dataset is
displayed correctly.

Thanks in advance for any help on this issue.

BR
Joakim
 
G

Ginny Caughey [MVP]

Joakim,

Generally strong typed DataSets won't work until .NetCF version 2 next year.
 
J

Joakim Englund

OK, thanks Ginny for the information.
Do you know if it is supported in VisualStudio 2005 Beta?
/Joakim
 
G

Ginny Caughey [MVP]

Joakim,

I can't remember if it's in there yet, sorry. The main problem is the
Serializable attribute since the current Comapct Framework doesn't support
serialization except in limited ways.
 
I

Ilya Tumanov [MS]

Typed DataSets are not supported on CF V1, sorry.
You can modify proxy code to use untyped DataSet instead.

Or, you can remove unsupported stuff form typed DataSet code so you can
compile it against CF.
The problem with that is what you would have to modify the code each time
proxy is regenerated.

By the way, it's not clear to me how exactly you're getting
TypeLoadException.
It should be impossible to compile proxy class for WS using typed DataSet's.
Are you compiling against desktop and trying to run this code on device?
If so, it won't work.

Best regards,

Ilya

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

Guest

Actually the answer is technically yes. If the question were worded using
the word "easily" then the answer would be no.

I use them all the time. First I model them in .NET then rip out all the the
stuff that CF.NET chokes on. The follow code, although 'junky' and
uneditted, still works. Pass in the dataset.vb file and the path to your new
CF.NET dataset.vb file.

Change the 'Insight...' namespace where needed. Also note that if you have
a timestamp field you might want to ommit it from you DataSet entirely like I
did with the 'TS' field.

Good luck.

Get ready to roll your selves up. (International Translation: This could be
difficult)
=====================================
Sub buildCeBusinessEntity(ByVal f1 As String, ByVal f2 As String)
Dim sw As StreamWriter = New StreamWriter(f2)
Dim sr As StreamReader = New StreamReader(f1)
Dim line As String
Dim line2 As String = ""
Dim newLine As String

Console.Write(f1)

Do

line = sr.ReadLine()

If Not line Is Nothing Then
'Console.WriteLine(line.Trim)
'Threading.Thread.CurrentThread.Sleep(1000)
Select Case line.Trim.ToLower
Case "Imports System".ToLower
newLine = line
sw.WriteLine("Imports Insight.Pocket.Common") ' For
StrongTypeException et al.
Case "<Serializable(), _".ToLower
newLine = " < _"
Case "System.Diagnostics.DebuggerStepThrough(),
_".ToLower
newLine = "
System.Diagnostics.DebuggerStepThrough()> _"
Case "System.ComponentModel.ToolboxItem(true)> _".ToLower
newLine = Nothing
Case "Protected Sub New(ByVal info As SerializationInfo,
ByVal context As StreamingContext)".ToLower
' Skip to end of function
While line2.Trim <> "End Sub"
line2 = sr.ReadLine
End While
newLine = ""
Case "<System.ComponentModel.Browsable(False), _".ToLower
newLine = ""
Case
"System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _".ToLower
newLine = ""
Case "Protected Overrides Sub ReadXmlSerializable(ByVal
reader As XmlReader)".ToLower
line2 = ""
'skip to end of function
While line2.Trim <> "End Sub"
line2 = sr.ReadLine
End While
newLine = ""
Case "Protected Overrides Function
GetSchemaSerializable() As System.Xml.Schema.XmlSchema".ToLower
line2 = ""
'skip to end of function
While line2.Trim <> "End Function"
line2 = sr.ReadLine
End While
newLine = ""
Case "<System.ComponentModel.Browsable(False)>
_".ToLower, "<System.ComponentModel.Browsable(True)> _".ToLower
newLine = ""
Case "Protected Overrides Function CreateInstance() As
DataTable".ToLower
newLine = " Protected Function CreateInstance() As
DataTable"
Case "Inherits DataSet".ToLower
newLine = "Inherits BaseDataSet"
Case Else
newLine = line
End Select

If Not line Is Nothing Then
If line.Trim.Length > 42 Then
If line.Trim.StartsWith("Me.Constraints.Add(New
UniqueConstraint") Then
Dim endAt As Integer = line.IndexOf(", true")
Dim startAt As Integer = line.IndexOf(""", ") + 2

line = line.Replace(", true", "")

line &= vbCrLf & "Me.PrimaryKey = " &
line.Substring(startAt, endAt - startAt)

newLine = line
End If
End If

If InStr(line, "TS") Then
If InStr(line, "Me.columnTS.ReadOnly = true") Then
newLine = Nothing
ElseIf InStr(line, "ByVal TS() As Byte, _") Then
newLine = Nothing
ElseIf InStr(line, "Private columnTS As DataColumn")
Then
newLine = Nothing
ElseIf InStr(line, "Public Property TS As Byte()")
Then
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()

newLine = Nothing
ElseIf InStr(line, "TSNull()") Then
sr.ReadLine()
sr.ReadLine()

newLine = Nothing
ElseIf InStr(line, "Friend ReadOnly Property
TSColumn As DataColumn") Then
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()
sr.ReadLine()

newLine = Nothing
ElseIf InStr(line, "Me.columnTS =
Me.Columns(""TS"")") Then
newLine = Nothing
ElseIf InStr(line, "Me.columnTS = New
DataColumn(""TS"", GetType(System.Byte()), Nothing,
System.Data.MappingType.Element)") Then
sr.ReadLine()
newLine = Nothing
ElseIf InStr(line, "Friend Sub New()") Then
newLine = "Public Sub New()" ' For use of Clone
method
ElseIf InStr(line, ", TS") Then
newLine = line.Replace(", TS", "")
End If
End If
End If

If InStr(line, "Friend Sub New()") Then
newLine = "Public Sub New()"
End If

If InStr(line, "Date.Parse(""" & Now.ToString("M/d/yyyy") &
" 12:00:00 PM"")") Then
newLine = line.Replace("Date.Parse(""" &
Now.ToString("M/d/yyyy") & " 12:00:00 PM"")", "Date.Parse(""1/01/0001
12:00:00 AM"")") 'Remember SQLCE MinDate is different
End If


If Not newLine Is Nothing Then
sw.WriteLine(newLine)
End If


'Console.WriteLine(newLine)
End If
Loop Until line Is Nothing
sr.Close()
sw.Close()

End Sub
=====================================

BaseDataSet.vb (I cannot take all the credit for this but also cannot
remember where the credit is due)
---------------------------------------
Public Class BaseDataSet
Inherits Data.DataSet

Public Sub New()
MyBase.New()
Me.CaseSensitive = True
End Sub

Public Sub New(ByVal dataSetName As String)
MyBase.New(dataSetName)
Me.CaseSensitive = True
End Sub


Public Overridable Function GetChanges(ByRef ds As Data.DataSet, ByVal
rowStates As System.Data.DataRowState) As Data.DataSet
' dataset that is returned
Dim dsChanges As Data.DataSet ' = ds.Clone

'add table
'dsChanges.Tables.Add(ds.Tables(0).Clone)


'loop through table and find changes
For Each row As Data.DataRow In ds.Tables(0).Rows
If row.RowState = rowStates Then
If dsChanges Is Nothing Then dsChanges = ds.Clone
dsChanges.Tables(0).ImportRow(row)
End If
Next

Return dsChanges
End Function

Public Overridable Function GetChanges(ByRef ds As Data.DataSet) As
Data.DataSet
'dataset that is returned
Dim dsChanges As Data.DataSet = ds.Clone

'add table
dsChanges.Tables.Add(ds.Tables(0).Clone)

' loop through table and find changes
For Each row As Data.DataRow In ds.Tables(0).Rows
If row.RowState = Data.DataRowState.Added OrElse row.RowState =
Data.DataRowState.Deleted OrElse row.RowState = Data.DataRowState.Modified
Then
dsChanges.Tables(0).ImportRow(row)
End If
Next

Return dsChanges
End Function

End Class

============================

StrongTypingException.vb
--------------------------
Public Class StrongTypingException
Inherits Exception

Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub

Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class



"Ilya Tumanov [MS]" said:
Typed DataSets are not supported on CF V1, sorry.
You can modify proxy code to use untyped DataSet instead.

Or, you can remove unsupported stuff form typed DataSet code so you can
compile it against CF.
The problem with that is what you would have to modify the code each time
proxy is regenerated.

By the way, it's not clear to me how exactly you're getting
TypeLoadException.
It should be impossible to compile proxy class for WS using typed DataSet's.
Are you compiling against desktop and trying to run this code on device?
If so, it won't work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "Joakim Englund" <[email protected]>
From: "Joakim Englund" <[email protected]>
Subject: Strongly typed datasets and .NET CF = System.TypeLoadException?
Date: Thu, 12 Aug 2004 16:43:52 +0200
Lines: 16
Organization: INTRESS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ns.intress.se 193.15.233.39
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59247
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi all!

Is it possible to use strongly typed datasets in .NET CF.

I'm calling a web service from a smart device application running on P PC
2002 that returns a strongly typed dataset. Immediately when the call is
made I get a System.TypeLoadException. If I run the same application on
Windows XP I don't get any exception and the strongly typed dataset is
displayed correctly.

Thanks in advance for any help on this issue.

BR
Joakim
 
G

Guest

Try xsdcf.exe from www.tmgdevelopment.co.uk

It creates a typed dataset for the cf.

Or, if you're willing to spend money (about $900) and you are using sql ce,
you could use deklarit (www.deklarit.com). It will generate a complete set
of typed datasets, dataAdapters and DataReaders for your entire db (one for
each table). That would be the tip of the iceberg for this tool. I've been
using it, with success, for a sql ce db with about 20+ tables. But, it took
a lot of pain to learn to use it, as it sometimes acts weird when you really
start using all the features. But, it has a free download/trial period. You
can build a complete set of typed datasets, etc, in less than an hour (I
would guess).

Ok, I'm not trying to sell the thing, just saying what I know. Like I said,
learning to use it was quite painful, and I'm ok with it now, but not super
happy or anything.

Pedro
 
J

Joakim Englund

Hi Ilya,

I've created the main project out of the Smart Device Application Template.
To this project I added a project created from the Class Library Template,
as a data tier. In the class library I added a web reference to some web
services.

I then reference the class library's web reference from the main project. I
compiled it and used the Pocket PC 2002 Emulator to run it on, then I get
the System.TypeLoadException. If I start the compiled application directly
on my Windows XP desktop it runs fine.

BR
/Joakim

"Ilya Tumanov [MS]" said:
Typed DataSets are not supported on CF V1, sorry.
You can modify proxy code to use untyped DataSet instead.

Or, you can remove unsupported stuff form typed DataSet code so you can
compile it against CF.
The problem with that is what you would have to modify the code each time
proxy is regenerated.

By the way, it's not clear to me how exactly you're getting
TypeLoadException.
It should be impossible to compile proxy class for WS using typed DataSet's.
Are you compiling against desktop and trying to run this code on device?
If so, it won't work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "Joakim Englund" <[email protected]>
From: "Joakim Englund" <[email protected]>
Subject: Strongly typed datasets and .NET CF = System.TypeLoadException?
Date: Thu, 12 Aug 2004 16:43:52 +0200
Lines: 16
Organization: INTRESS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ns.intress.se 193.15.233.39
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59247
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi all!

Is it possible to use strongly typed datasets in .NET CF.

I'm calling a web service from a smart device application running on P PC
2002 that returns a strongly typed dataset. Immediately when the call is
made I get a System.TypeLoadException. If I run the same application on
Windows XP I don't get any exception and the strongly typed dataset is
displayed correctly.

Thanks in advance for any help on this issue.

BR
Joakim
 
I

Ilya Tumanov [MS]

I see. As I suspected, you're compiling this proxy against desktop.

That won't work even if you change the proxy to be CF compatible as
assemblies compiled against desktop can not be used on CF.
Instead of choosing "Class Library" for this DLL you should select
"SmartDeviceApplication" and choose "Class Library" in the Smart Device
Application Wizard.
As soon as you do that, you won't be able to compile this proxy unless you
remove unsupported stuff from it.

Best regards,

Ilya

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

--------------------
Reply-To: "Joakim Englund" <[email protected]>
From: "Joakim Englund" <[email protected]>
References: <[email protected]>
Subject: Re: Strongly typed datasets and .NET CF = System.TypeLoadException?
Date: Fri, 13 Aug 2004 07:48:27 +0200
Lines: 78
Organization: INTRESS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ns.intress.se 193.15.233.39
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59297
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi Ilya,

I've created the main project out of the Smart Device Application Template.
To this project I added a project created from the Class Library Template,
as a data tier. In the class library I added a web reference to some web
services.

I then reference the class library's web reference from the main project. I
compiled it and used the Pocket PC 2002 Emulator to run it on, then I get
the System.TypeLoadException. If I start the compiled application directly
on my Windows XP desktop it runs fine.

BR
/Joakim

"Ilya Tumanov [MS]" said:
Typed DataSets are not supported on CF V1, sorry.
You can modify proxy code to use untyped DataSet instead.

Or, you can remove unsupported stuff form typed DataSet code so you can
compile it against CF.
The problem with that is what you would have to modify the code each time
proxy is regenerated.

By the way, it's not clear to me how exactly you're getting
TypeLoadException.
It should be impossible to compile proxy class for WS using typed DataSet's.
Are you compiling against desktop and trying to run this code on device?
If so, it won't work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Reply-To: "Joakim Englund" <[email protected]>
From: "Joakim Englund" <[email protected]>
Subject: Strongly typed datasets and .NET CF = System.TypeLoadException?
Date: Thu, 12 Aug 2004 16:43:52 +0200
Lines: 16
Organization: INTRESS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: ns.intress.se 193.15.233.39
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:59247
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi all!

Is it possible to use strongly typed datasets in .NET CF.

I'm calling a web service from a smart device application running on P PC
2002 that returns a strongly typed dataset. Immediately when the call is
made I get a System.TypeLoadException. If I run the same application on
Windows XP I don't get any exception and the strongly typed dataset is
displayed correctly.

Thanks in advance for any help on this issue.

BR
Joakim
 

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