S
Schorschi
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);
}
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);
}