473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.XmlN ode) As Object Implements
System.Configur ation.IConfigur ationSectionHan dler.Create

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

'

theNavigator = theNode.CreateN avigator
theDescriptor = CType(theNaviga tor.Evaluate("s tring(@type)"),
String)
theType = theDescriptor.G etType

theSerializer = New XmlSerializer(t heType)
theReader = New XmlNodeReader(t heNode)

If (theSerializer. CanDeserialize( theReader)) Then

Create = theSerializer.D eserialize(theR eader)

End If

Return (Create)

End Function

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

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="ProgramIn fo"
type="ConfigSec tionHandler.Con figSectionHandl er, ConfigSectionHa ndler"
/>
</configSections>
<ProgramInfo type="ConfigSec tionObjects.Pro gramInfo,
ConfigSectionOb jects">
<Name>ConfigSec tionDemo</Name>
<Language>C#</Language>
<Level>Intermed iate</Level>
</ProgramInfo>
</configuration>

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

public object Create(object parent, object configContext,
System.Xml.XmlN ode section)
{
XPathNavigator xNav=section.Cr eateNavigator() ;
string typeOfObject=(s tring) xNav.Evaluate(" string(@type)") ;
Type t=Type.GetType( typeOfObject);
XmlSerializer ser=new XmlSerializer(t );
XmlNodeReader xNodeReader=new XmlNodeReader(s ection);
return ser.Deserialize (xNodeReader);
}
Nov 21 '05 #1
3 1772
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*******@DSLE xtreme.COM> schreef in bericht
news:21******** *************** ***@posting.goo gle.com...
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.XmlN ode) As Object Implements
System.Configur ation.IConfigur ationSectionHan dler.Create

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

'

theNavigator = theNode.CreateN avigator
theDescriptor = CType(theNaviga tor.Evaluate("s tring(@type)"),
String)
theType = theDescriptor.G etType

theSerializer = New XmlSerializer(t heType)
theReader = New XmlNodeReader(t heNode)

If (theSerializer. CanDeserialize( theReader)) Then

Create = theSerializer.D eserialize(theR eader)

End If

Return (Create)

End Function

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

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<section name="ProgramIn fo"
type="ConfigSec tionHandler.Con figSectionHandl er, ConfigSectionHa ndler"
/>
</configSections>
<ProgramInfo type="ConfigSec tionObjects.Pro gramInfo,
ConfigSectionOb jects">
<Name>ConfigSec tionDemo</Name>
<Language>C#</Language>
<Level>Intermed iate</Level>
</ProgramInfo>
</configuration>

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

public object Create(object parent, object configContext,
System.Xml.XmlN ode section)
{
XPathNavigator xNav=section.Cr eateNavigator() ;
string typeOfObject=(s tring) xNav.Evaluate(" string(@type)") ;
Type t=Type.GetType( typeOfObject);
XmlSerializer ser=new XmlSerializer(t );
XmlNodeReader xNodeReader=new XmlNodeReader(s ection);
return ser.Deserialize (xNodeReader);
}

Nov 21 '05 #2
On 2004-09-04, Schorschi <Sc*******@DSLE xtreme.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.G etType
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(th eDescriptor)


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
2879
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
2027
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 machine (Win2003 Advanced Server), also place of generation of HLP files (using HCW-Help Workshop Compiler)) Problem: When trying to call help file from module (fmx) (ON runtime machine) by pressing F1 (help key),. system seems not to react at all....
0
2249
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) in the user's registry. The latest e-mail we received from development states: "Launching help with a certain topic using a Map ID is not supported in the C#.NET API. Well there is always a work around but would violate the .NET help...
2
1734
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 describing the benefits of either or the other? -- <%= Clinton Gallagher, "Twice the Results -- Half the Cost" Architectural & e-Business Consulting -- Software Development NET csgallagher@REMOVETHISTEXTmetromilwaukee.com
0
301
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 very small size. Smaller than any page that's going to be displayed. It's a real pain. ShowHelp does not let you set the size. I can't find anyway to get a hold of the help window after it's created so I can't hit it with the resize hammer.
6
4331
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 result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3351
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 numarray, help gives unhelpful responses:
2
2544
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
1761
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 application form. I understand there are other ways of doing help files, but are these possible, what is the easiest and how much work is it? dixie
8
3222
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 including search the internet for help, but the help is worthless. Any ideas?
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.