473,378 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

HELP! Why is this XMLSerializer Code Wacked?

The following code works fine until I check the .CanDeserialize flag

The exact same code in C# works, but in VB .NET? AUGH! HELP!

----------------------------------

Public Function Create(ByVal theOwner As Object, ByVal theContext As
Object, ByVal theNode As System.Xml.XmlNode) As Object Implements
System.Configuration.IConfigurationSectionHandler. Create

Dim theNavigator As XPathNavigator, _
theDescriptor As String, _
theType As Type, _
theSerializer As XmlSerializer, _
theReader As XmlNodeReader

'

theNavigator = theNode.CreateNavigator
theDescriptor = CType(theNavigator.Evaluate("string(@type)"),
String)
theType = theDescriptor.GetType

theSerializer = New XmlSerializer(theType)
theReader = New XmlNodeReader(theNode)

If (theSerializer.CanDeserialize(theReader)) Then

Create = theSerializer.Deserialize(theReader)

End If

Return (Create)

End Function

----------------------------------
Here is the XML Doc...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ProgramInfo"
type="ConfigSectionHandler.ConfigSectionHandler, ConfigSectionHandler"
/>
</configSections>
<ProgramInfo type="ConfigSectionObjects.ProgramInfo,
ConfigSectionObjects">
<Name>ConfigSectionDemo</Name>
<Language>C#</Language>
<Level>Intermediate</Level>
</ProgramInfo>
</configuration>

----------------------------------
C# Code...

public object Create(object parent, object configContext,
System.Xml.XmlNode section)
{
XPathNavigator xNav=section.CreateNavigator();
string typeOfObject=(string) xNav.Evaluate("string(@type)");
Type t=Type.GetType(typeOfObject);
XmlSerializer ser=new XmlSerializer(t);
XmlNodeReader xNodeReader=new XmlNodeReader(section);
return ser.Deserialize(xNodeReader);
}
Nov 21 '05 #1
3 1753
I don't know why it is wacked, who made it?

:-)

We had just a long discussion in this newsgroup why something in C# works
and not in VBNet the end conlclussion from both the C# guy and the VBNet
guys was that there was a little different in implementation. In this case
the all found the VBNet way was better.

So maybe it is much easier to tell what you want to archieve using VBNet,
transporting 1 by 1 to another language from code has never been the best
solution.

Just my thought,

Cor
"Schorschi" <Sc*******@DSLExtreme.COM> schreef in bericht
news:21**************************@posting.google.c om...
The following code works fine until I check the .CanDeserialize flag

The exact same code in C# works, but in VB .NET? AUGH! HELP!

----------------------------------

Public Function Create(ByVal theOwner As Object, ByVal theContext As
Object, ByVal theNode As System.Xml.XmlNode) As Object Implements
System.Configuration.IConfigurationSectionHandler. Create

Dim theNavigator As XPathNavigator, _
theDescriptor As String, _
theType As Type, _
theSerializer As XmlSerializer, _
theReader As XmlNodeReader

'

theNavigator = theNode.CreateNavigator
theDescriptor = CType(theNavigator.Evaluate("string(@type)"),
String)
theType = theDescriptor.GetType

theSerializer = New XmlSerializer(theType)
theReader = New XmlNodeReader(theNode)

If (theSerializer.CanDeserialize(theReader)) Then

Create = theSerializer.Deserialize(theReader)

End If

Return (Create)

End Function

----------------------------------
Here is the XML Doc...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ProgramInfo"
type="ConfigSectionHandler.ConfigSectionHandler, ConfigSectionHandler"
/>
</configSections>
<ProgramInfo type="ConfigSectionObjects.ProgramInfo,
ConfigSectionObjects">
<Name>ConfigSectionDemo</Name>
<Language>C#</Language>
<Level>Intermediate</Level>
</ProgramInfo>
</configuration>

----------------------------------
C# Code...

public object Create(object parent, object configContext,
System.Xml.XmlNode section)
{
XPathNavigator xNav=section.CreateNavigator();
string typeOfObject=(string) xNav.Evaluate("string(@type)");
Type t=Type.GetType(typeOfObject);
XmlSerializer ser=new XmlSerializer(t);
XmlNodeReader xNodeReader=new XmlNodeReader(section);
return ser.Deserialize(xNodeReader);
}

Nov 21 '05 #2
On 2004-09-04, Schorschi <Sc*******@DSLExtreme.COM> wrote:
The following code works fine until I check the .CanDeserialize flag

The exact same code in C# works, but in VB .NET? AUGH! HELP!
As you suspect, it's a translation problem...

In VB.Net theType = theDescriptor.GetType
is not the same as C#.
Type t=Type.GetType(typeOfObject);


In fact, both languages work identically here, what you want is...

theType = Type.GetType(theDescriptor)


Nov 21 '05 #3
I am trying to load the custom config section name in the .config
file. Using deserialize method seemed effective, since I can later
serialize the section parameters later if needed. I found the C#
example, but for the client I have, the source must be in VB .NET...
weird since C# is so interchange-able? But given the client, and how
they are still learning VB.NET for their own internal use, I guess it
makes sense. They are having real trouble going form VB 6 to VB.NET
(people pulling their hair out).

What I can NOT understand is why this code does not work. It looks
fine, but chokes. Thought I would ask the gurus what the heck is
wrong with it.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
0
by: Tim21 | last post by:
OK, im miserable :)) so.. help'd b highly appreciated. Situation: Win XP aplication server RUNTIME (stored fmx files along with the ..hlp files) Fmx's generated and compiled on development...
0
by: Denise L. Moss-Fritch | last post by:
Has anyone developed context sensitive help for a C# application? According to our programming staff, the development side is not able to provide links without adding hard coded links (topic names)...
2
by: clintonG | last post by:
Is there a document that explains the difference between the Visual Studio .NET 2003 Combined Help Collection and the MSDN Library for Visual Studio .NET 2003 or does someone have comments...
0
by: Larry Fix | last post by:
I recently added help to a C# application using the Help.ShowHelp method. My compiled help file gets display so that's good. What's not so good is that the help window always starts out with a...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
5
by: dixie | last post by:
I was wondering if there is a way of doing a simple help system with either viewing a page in a browser or looking at a definite page in a .pdf file when a help button was pushed on an Access...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.