By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,112 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

Problems with GetType in VB.NET

P: n/a
Hi All.

I have been converting a C# to VB.NET Web Project and I have one last
issue to contend with.

I have included relevant code below and an explanation of the error..

Public Function LoadMenuFromFile(ByVal filePath As String) As
MenuDataSet
Dim cacheKey As String = filePath

Dim ds As MenuDataSet = CType(Cache(cacheKey), MenuDataSet)
If ds Is Nothing Then
'bind the menu
Dim serializer As XmlSerializer = New
XmlSerializer(Type.GetType(MenuDataSet))

***** error above line Type.GetType(MenuDataSet) ******

The error is a compiler error stating that MenuDataSet is a type and
cannot be used as an expression.

MenuDataSet is a class as shown below:

Public Class MenuDataSet
Implements ICloneable

Public Sections() As MenuSection
'/ <summary>
'/ Merges the provided data set with this dataset placing the
sections before or after
'/ the existing data.
'/ </summary>
'/ <param name="ds">The data set to merge with.</param>
'/ <param name="opt">The location where to merge the provided
data.</param>
Public Sub Merge(ds As MenuDataSet, opt As MergeLocation)
'check for nulls
If ds.Sections Is Nothing OrElse ds.Sections.Length = 0 Then
Return
End If
'check for nulls
If Sections Is Nothing OrElse Sections.Length = 0 Then
Sections = CType(ds.Sections.Clone(), MenuSection())
Return
End If

'create new array
Dim newItems(Sections.Length + ds.Sections.Length) As
MenuSection
Select Case opt
Case MergeLocation.Before
Array.Copy(ds.Sections, 0, newItems, 0,
ds.Sections.Length)
Array.Copy(Sections, 0, newItems, ds.Sections.Length,
Sections.Length)

Case MergeLocation.After
Array.Copy(Sections, 0, newItems, 0, Sections.Length)
Array.Copy(ds.Sections, 0, newItems, Sections.Length,
ds.Sections.Length)
End Select

Me.Sections = newItems
End Sub 'Merge
'/ <summary>
'/ Copy all data set elements
'/ </summary>
'/ <returns>A copy of this data set</returns>
Public Function Clone() As Object Implements System.ICloneable.Clone
Dim ds As New MenuDataSet
If Not (Sections Is Nothing) Then
ds.Sections = New MenuSection(Sections.Length) {}
Dim i As Integer

While i < Sections.Length
ds.Sections(i) = CType(Sections(i).Clone(), MenuSection)
i += 1
End While
End If
Return ds
End Function 'Clone
End Class 'MenuDataSet
Has anyone got any ideas as to why it wont accept the class for the
GetType area?

Thanks,
Robert

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<ro****@joshie.com.au> schrieb
Dim serializer As XmlSerializer = New
XmlSerializer(Type.GetType(MenuDataSet))

***** error above line Type.GetType(MenuDataSet) ******

The error is a compiler error stating that MenuDataSet is a type
and cannot be used as an expression.

MenuDataSet is a class as shown below:

Dim serializer As XmlSerializer = New
XmlSerializer(GetType(MenuDataSet))
GetType is a VB keyword returning a System.Type object representing the
MenuDataSet type.

Armin

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.