473,387 Members | 1,493 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,387 software developers and data experts.

serializer object and its constructor failing on me

Hi all,

i'm trying to serialize a class. Using the constructor of
XmlSerializer i get these (odd?) errors: "File or assembly name
goseij9w.dll, or one of its dependencies, was not found". Everytime i
run the testprogram it complains about another exotically named dll
like et_kn-hl.dll or afeaqisr.dll.
Even the example from msdn throws these errors.

Anyone knows wuts wrong?
I'll post the example code below.

Thanks in advance,

grtz,

Mark

<code>
Imports System
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports Microsoft.VisualBasic

Public Class msdn_example
' The XmlRootAttribute allows you to set an alternate name
' (PurchaseOrder) of the XML element, the element namespace; by
' default, the XmlSerializer uses the class name. The attribute
' also allows you to set the XML namespace for the element.
Lastly,
' the attribute sets the IsNullable property, which specifies
whether
' the xsi:null attribute appears if the class instance is set to
' a null reference.
<XmlRootAttribute("PurchaseOrder", _
Namespace:="http://www.cpandl.com", IsNullable:=False)> _
Public Class PurchaseOrder

Public ShipTo As Address
Public OrderDate As String
' The XmlArrayAttribute changes the XML element name
' from the default of "OrderedItems" to "Items".
<XmlArrayAttribute("Items")> _
Public OrderedItems() As OrderedItem
Public SubTotal As Decimal
Public ShipCost As Decimal
Public TotalCost As Decimal
End Class 'PurchaseOrder
Public Class Address
' The XmlAttribute instructs the XmlSerializer to serialize
the Name
' field as an XML attribute instead of an XML element (the
default
' behavior).
<XmlAttributeAttribute()> _
Public Name As String
Public Line1 As String

' Setting the IsNullable property to false instructs the
' XmlSerializer that the XML attribute will not appear if
' the City field is set to a null reference.
<XmlElementAttribute(IsNullable:=False)> _
Public City As String
Public State As String
Public Zip As String
End Class 'Address
Public Class OrderedItem
Public ItemName As String
Public Description As String
Public UnitPrice As Decimal
Public Quantity As Integer
Public LineTotal As Decimal
' Calculate is a custom method that calculates the price per
item,
' and stores the value in a field.
Public Sub Calculate()
LineTotal = UnitPrice * Quantity
End Sub 'Calculate
End Class 'OrderedItem
Public Class Test

Public Shared Sub Main()
' Read and write purchase orders.
Dim t As New Test
t.CreatePO("po.xml")
t.ReadPO("po.xml")
End Sub 'Main

Private Sub CreatePO(ByVal filename As String)
' Create an instance of the XmlSerializer class;
' specify the type of object to serialize.
Dim serializer As New
XmlSerializer(GetType(PurchaseOrder))
Dim writer As New StreamWriter(filename)
Dim po As New PurchaseOrder

' Create an address to ship and bill to.
Dim billAddress As New Address
billAddress.Name = "Teresa Atkinson"
billAddress.Line1 = "1 Main St."
billAddress.City = "AnyTown"
billAddress.State = "WA"
billAddress.Zip = "00000"
' Set ShipTo and BillTo to the same addressee.
po.ShipTo = billAddress
po.OrderDate = System.DateTime.Now.ToLongDateString()

' Create an OrderedItem object.
Dim i1 As New OrderedItem
i1.ItemName = "Widget S"
i1.Description = "Small widget"
i1.UnitPrice = CDec(5.23)
i1.Quantity = 3
i1.Calculate()

' Insert the item into the array.
Dim items(0) As OrderedItem
items(0) = i1
po.OrderedItems = items
' Calculate the total cost.
Dim subTotal As New Decimal
Dim oi As OrderedItem
For Each oi In items
subTotal += oi.LineTotal
Next oi
po.SubTotal = subTotal
po.ShipCost = CDec(12.51)
po.TotalCost = po.SubTotal + po.ShipCost
' Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po)
writer.Close()
End Sub 'CreatePO

Protected Sub ReadPO(ByVal filename As String)
' Create an instance of the XmlSerializer class;
' specify the type of object to be deserialized.

<HERE IS WHERE IT DOESN'T GO ALL THAT WELL>
Dim serializer As New
XmlSerializer(GetType(PurchaseOrder))
</HERE IS WHERE IT DOESN'T GO ALL THAT WELL>

' If the XML document has been altered with unknown
' nodes or attributes, handle them with the
' UnknownNode and UnknownAttribute events.
AddHandler serializer.UnknownNode, AddressOf
serializer_UnknownNode
AddHandler serializer.UnknownAttribute, AddressOf
serializer_UnknownAttribute

' A FileStream is needed to read the XML document.
Dim fs As New FileStream(filename, FileMode.Open)
' Declare an object variable of the type to be
deserialized.
Dim po As PurchaseOrder
' Use the Deserialize method to restore the object's state
with
' data from the XML document.
po = CType(serializer.Deserialize(fs), PurchaseOrder)
' Read the order date.
Console.WriteLine(("OrderDate: " & po.OrderDate))

' Read the shipping address.
Dim shipTo As Address = po.ShipTo
ReadAddress(shipTo, "Ship To:")
' Read the list of ordered items.
Dim items As OrderedItem() = po.OrderedItems
Console.WriteLine("Items to be shipped:")
Dim oi As OrderedItem
For Each oi In items
Console.WriteLine((ControlChars.Tab & oi.ItemName &
ControlChars.Tab & _
oi.Description & ControlChars.Tab & oi.UnitPrice &
ControlChars.Tab & _
oi.Quantity & ControlChars.Tab & oi.LineTotal))
Next oi
' Read the subtotal, shipping cost, and total cost.
Console.WriteLine((New String(ControlChars.Tab, 5) & _
" Subtotal" & ControlChars.Tab & po.SubTotal))
Console.WriteLine(New String(ControlChars.Tab, 5) & _
" Shipping" & ControlChars.Tab & po.ShipCost)
Console.WriteLine(New String(ControlChars.Tab, 5) & _
" Total" & New String(ControlChars.Tab, 2) & po.TotalCost)
End Sub 'ReadPO

Protected Sub ReadAddress(ByVal a As Address, ByVal label As
String)
' Read the fields of the Address object.
Console.WriteLine(label)
Console.WriteLine(ControlChars.Tab & a.Name)
Console.WriteLine(ControlChars.Tab & a.Line1)
Console.WriteLine(ControlChars.Tab & a.City)
Console.WriteLine(ControlChars.Tab & a.State)
Console.WriteLine(ControlChars.Tab & a.Zip)
Console.WriteLine()
End Sub 'ReadAddress

Protected Sub serializer_UnknownNode(ByVal sender As Object,
ByVal e As XmlNodeEventArgs)
Console.WriteLine(("Unknown Node:" & e.Name &
ControlChars.Tab & e.Text))
End Sub 'serializer_UnknownNode
Protected Sub serializer_UnknownAttribute(ByVal sender As
Object, ByVal e As XmlAttributeEventArgs)
Dim attr As System.Xml.XmlAttribute = e.Attr
Console.WriteLine(("Unknown attribute " & attr.Name & "='"
& attr.Value & "'"))
End Sub 'serializer_UnknownAttribute
End Class 'Test

End Class
</code>
Jul 21 '05 #1
0 1459

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
22
by: Peter Ammon | last post by:
A friend was asked "How many ways are there to create an object in C++?" in an interview. Apparently, the "right" answer was eleven. Does anyone know how the interviewer arrived at that number? ...
3
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
0
by: Albert Jan | last post by:
Hi, I use the XmlSerializer in C# to serialize an object containing an email message to xml. This works often fine, but for some mailmessages the serialization fails with the message 'There was...
6
by: Wilfried Mestdagh | last post by:
Hi, I use this class to save application settings in a xml file. Sometime I have exception error in the Load method, and sometime in the Save method. Is this a bug in NET or is there something I...
0
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
4
by: mkadlec99 | last post by:
Got a remoting question I was hoping someone could solve. I have an object (UpdateFlifo) that has two constructors, one empty, and one with arguments. I want to expose this object remotely,...
9
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.