Click here to Skip to main content
16,008,010 members
Home / Discussions / C#
   

C#

 
AnswerRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
OriginalGriff29-May-19 23:00
mveOriginalGriff29-May-19 23:00 
AnswerRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
#realJSOP30-May-19 4:55
professional#realJSOP30-May-19 4:55 
GeneralRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
Eddy Vluggen30-May-19 7:20
professionalEddy Vluggen30-May-19 7:20 
GeneralRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
#realJSOP30-May-19 7:24
professional#realJSOP30-May-19 7:24 
PraiseRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
Eddy Vluggen30-May-19 7:29
professionalEddy Vluggen30-May-19 7:29 
SuggestionRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
Richard Deeming30-May-19 7:46
mveRichard Deeming30-May-19 7:46 
GeneralRe: Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way Pin
#realJSOP1-Jun-19 5:02
professional#realJSOP1-Jun-19 5:02 
QuestionFile keeps getting corrupted on just one machine Pin
jkirkerx29-May-19 12:51
professionaljkirkerx29-May-19 12:51 
Whoops, wrong forum

I wrote a Win Forms app in vb, and took the advice to not use the registry, so I created an appSettings.json file that I store in the appData folder. It works fine on my machine, and on 7 others, but the file gets corrupt on one machine, in which an extra } is placed at the end of the json file. Then I go to read the file and my code bombs during deserialize.

What have I done, well I tried to streamline and optimize the code as much as possible. At this point I have run out of things to search for.
Public Shared Function GetSettings() As RootObject

            Dim oRootObject As RootObject = Nothing
            Dim appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
            Dim appPath = appData + My.Resources.AppSettingsJsonPath
            If Not (File.Exists(appPath)) Then
                Create_AppSettings()
            End If

            Try

                Using jsonStream = New FileStream(appPath, FileMode.Open, FileAccess.Read)

                    Dim fileLen = jsonStream.Length
                    Dim fileData = New Byte(fileLen) {}
                    Dim jsonLen = jsonStream.Read(fileData, 0, fileLen)
                    Dim fileText = Encoding.UTF8.GetString(fileData)
                    oRootObject = JsonConvert.DeserializeObject(Of RootObject)(fileText)

                End Using

            Catch ex As Exception
                ErrorLogging.NLog_Exception(ex, "Read appSettings.json")
            End Try

            Return oRootObject

        End Function
Public Shared Sub WriteSettings(ByVal rootObject As RootObject)

            Dim appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
            Dim appPath = appData + My.Resources.AppSettingsJsonPath
            If Not (IsFileInUse(appPath)) Then

                If rootObject.ProductInfo IsNot Nothing Then
                    rootObject.ProductInfo.Name = Application.ProductName
                    rootObject.ProductInfo.Version = Application.ProductVersion
                End If

                If rootObject.Settings IsNot Nothing Then
                    rootObject.Settings.Version = Application.ProductVersion
                End If

                Try

                    Dim oJs = JsonConvert.SerializeObject(rootObject, Formatting.Indented)
                    Do Until Not IsFileInUse(appPath)
                        Application.DoEvents()
                    Loop
                    Dim bytes() = New UTF8Encoding(True).GetBytes(oJs)
                    Using jsonStream = File.OpenWrite(appPath)
                        jsonStream.Write(bytes, 0, bytes.Length)
                    End Using

                Catch ex As Exception
                    ErrorLogging.NLog_Exception(ex, "Write appSettings.json")
                End Try

            End If

        End Sub
If it ain't broke don't fix it
Discover my world at jkirkerx.com


modified 29-May-19 19:06pm.

AnswerRe: File keeps getting corrupted on just one machine PinPopular
Dave Kreskowiak29-May-19 13:11
mveDave Kreskowiak29-May-19 13:11 
GeneralRe: File keeps getting corrupted on just one machine Pin
jkirkerx29-May-19 13:17
professionaljkirkerx29-May-19 13:17 
AnswerRe: File keeps getting corrupted on just one machine Pin
Dave Kreskowiak29-May-19 13:13
mveDave Kreskowiak29-May-19 13:13 
GeneralRe: File keeps getting corrupted on just one machine Pin
jkirkerx29-May-19 13:25
professionaljkirkerx29-May-19 13:25 
QuestionDownload files Pin
Member 1447263829-May-19 0:23
Member 1447263829-May-19 0:23 
AnswerRe: Download files Pin
#realJSOP29-May-19 0:36
professional#realJSOP29-May-19 0:36 
AnswerRe: Download files Pin
Pete O'Hanlon29-May-19 0:42
mvePete O'Hanlon29-May-19 0:42 
GeneralRe: Download files Pin
Member 1447263829-May-19 3:12
Member 1447263829-May-19 3:12 
GeneralRe: Download files Pin
OriginalGriff29-May-19 3:14
mveOriginalGriff29-May-19 3:14 
GeneralRe: Download files Pin
Pete O'Hanlon29-May-19 3:36
mvePete O'Hanlon29-May-19 3:36 
Questiondownload files Pin
Member 1447263829-May-19 1:30
Member 1447263829-May-19 1:30 
QuestionRe: download files Pin
Richard MacCutchan28-May-19 21:11
mveRichard MacCutchan28-May-19 21:11 
AnswerRe: download files Pin
Member 1447263829-May-19 0:23
Member 1447263829-May-19 0:23 
GeneralRe: download files Pin
Richard MacCutchan29-May-19 1:35
mveRichard MacCutchan29-May-19 1:35 
AnswerRe: download files Pin
Richard Deeming29-May-19 0:42
mveRichard Deeming29-May-19 0:42 
QuestionC# using get set. Why is this failing? Pin
Brian_TheLion28-May-19 19:52
Brian_TheLion28-May-19 19:52 
AnswerRe: C# using get set. Why is this failing? Pin
Member 1356638328-May-19 20:14
Member 1356638328-May-19 20:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.