I have created a console application in dot net core 3.1 which changes the values of existing json file on running. I created the exe file by using following command :
dotnet publish -r win-x86 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
here is the code for my application:
static void Main (string[] args) {
try {
// blah blah.. some code to get liscence period
if (DateTime.Now <= liscencePeriod) {
var processor = new JsonDataProcessor ();
processor.AmmendJsonData ();
}
}
} catch (Exception ex) {
var errorFile = Path.Combine (Environment.CurrentDirectory, "JsonEditorError.txt");
File.WriteAllText (errorFile, $"{ex.Message}");
}
}
//AmmendJsonData code inside JsonDataProcessor class
internal void AmmendJsonData () {
try {
var jsonPath = Path.Combine (Environment.CurrentDirectory, "AVLJsonFile.json");
var jsonData = File.ReadAllText (jsonPath);
var jsonSchema = JsonConvert.DeserializeObject<Root> (jsonData);
ChangeJsonContent (jsonSchema);
var newJson = JsonConvert.SerializeObject (jsonSchema, Formatting.Indented);
File.WriteAllText (jsonPath, newJson);
} catch (Exception ex) {
throw ex;
}
}
This exe runs fine for few days but after that it stops working and data in json file doesn't change.. I also don't get any error. Please let me know whats going wrong here.