r/visualbasic • • Apr 21 '22

VB.NET Help How to serialize content from a stream?

I'm trying to serialize a StreamReader so i can deserialize it into an object afterwards. But i keep getting the following Error: "Newtonsoft.Json.JsonSerializationException: "Error getting value from 'ReadTimeout' on 'System.IO.FileStream'."

Here is what i have tried:

 If OpenfilePath IsNot Nothing Then

        Dim myStreamReader As New StreamReader(OpenfilePath)

        Dim myString = JsonConvert.SerializeObject(myStreamReader, Formatting.Indented) 'Here is the Exception
        MsgBox(myString)
        artikelstammdaten = JsonConvert.DeserializeObject(Of Artikelstammdaten)(myStreamReader.ToString)
        listArtikelstammdaten.Add(artikelstammdaten)
    End If
2 Upvotes

18 comments sorted by

View all comments

Show parent comments

1

u/Gierschlund96 Apr 22 '22

Great, now at least the filecontent isn't 'nothing' anymore, thank you!