onedizzydevil
Programmer
I am trying to convert the following C# code:
to VB.NET, I used an online converter to receive the following code but it does not work.
I get the following error:
The root element is missing.
Any assistance would be greatly appreciated.
Wayne Sellars
"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
Code:
private Stream GetXmlTemplate() {
if (this.Cache.Get(this.XmlTemplate) != null) {
MemoryStream ms = (MemoryStream)this.Cache.Get(this.XmlTemplate);
ms.Position = 0;
return CopyStream(ms);
} else {
FileStream fs = null;
try {
fs = new FileStream(this.XmlTemplate,FileMode.Open,FileAccess.Read);
MemoryStream ms = new MemoryStream();
byte[] bytes = new byte[1024];
int i;
while ((i = fs.Read(bytes,0,bytes.Length)) != 0) {
ms.Write(bytes,0,i);
}
ms.Position = 0;
CacheDependency dep = new CacheDependency(new string[]{this.XmlTemplate});
this.Cache.Insert(this.XmlTemplate,ms,dep);
return CopyStream(ms);
}
catch (Exception exp) {
throw new ApplicationException(String.Concat("Unable to cache XML template (",exp.Message,"): ",this.XmlTemplate));
}
finally {
fs.Close();
}
}
}
to VB.NET, I used an online converter to receive the following code but it does not work.
Code:
Private Function GetXmlTemplate() As Stream
If Not Me.Cache.Get(Me.XmlTemplate) Is Nothing Then
Dim ms As MemoryStream = CType(Me.Cache.Get(Me.XmlTemplate), MemoryStream)
ms.Position = 0
Return CopyStream(ms)
Else
Dim fs As FileStream = Nothing
Try
fs = New FileStream(Me.XmlTemplate, FileMode.Open, FileAccess.Read)
Dim ms As MemoryStream = New MemoryStream
Dim bytes(1024) As Byte
Dim i As Integer
While (CType(i = fs.Read(bytes, 0, bytes.Length), Integer) > 0)
ms.Write(bytes, 0, i)
End While
ms.Position = 0
Dim dep As CacheDependency = New CacheDependency(New String() {Me.XmlTemplate})
Me.Cache.Insert(Me.XmlTemplate, ms, dep)
Return CopyStream(ms)
Catch exp As Exception
Throw New ApplicationException(String.Concat("Unable to cache XML template (", exp.Message, "): ", Me.XmlTemplate))
Finally
fs.Close()
End Try
End If
End Function
I get the following error:
The root element is missing.
Any assistance would be greatly appreciated.
Wayne Sellars
"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."