C
C#13mo ago
Jarski

❔ "string was not recognised as valid DateTime"

trying to make a super simple custom backup program that backs up my win user folder to a network share, I can run the program fine on my pc but as soon as i try the build/publish on another pc, i get the error "string was not recognised as valid DateTime." I have parsed the string so it should be good, but obviously not. am i blind? and yes everything is shoved together, im not the cleanest coder in the west and ive had chatgpt help me along the way. https://paste.ofcode.org/LeEn8UGHtixCHGKq9hGsJb
20 Replies
TheRanger
TheRanger13mo ago
which line throws that error and what is the value of the string?
Angius
Angius13mo ago
Is the string ISO8601?
Jarski
JarskiOP13mo ago
no idea, i reference datetime strings a couple times. trying to find where it actually saves the properties. heres the properties:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="FileBackupApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<FileBackupApp.Properties.Settings>
<setting name="SourceDirectory" serializeAs="String">
<value />
</setting>
<setting name="DestinationDirectory" serializeAs="String">
<value />
</setting>
<setting name="LastBackupTime" serializeAs="String">
<value />
</setting>
<setting name="UserDefinedBackupTime" serializeAs="String">
<value>00:00:00</value>
</setting>
</FileBackupApp.Properties.Settings>
</userSettings>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="FileBackupApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<FileBackupApp.Properties.Settings>
<setting name="SourceDirectory" serializeAs="String">
<value />
</setting>
<setting name="DestinationDirectory" serializeAs="String">
<value />
</setting>
<setting name="LastBackupTime" serializeAs="String">
<value />
</setting>
<setting name="UserDefinedBackupTime" serializeAs="String">
<value>00:00:00</value>
</setting>
</FileBackupApp.Properties.Settings>
</userSettings>
</configuration>
TheRanger
TheRanger13mo ago
wrap ur xml like this ```xml // your xml ```
Jarski
JarskiOP13mo ago
apologies, using wrong key
TheRanger
TheRanger13mo ago
i mean visual studio can tell you which line throws the error and you can debug its value
Jarski
JarskiOP13mo ago
It's not throwing the error on visual studio. It works just fine running as a build from vs
TheRanger
TheRanger13mo ago
i assume its trying to parse this? 00:00:00
MODiX
MODiX13mo ago
TheRanger
REPL Result: Success
DateTime.Parse("00:00:00")
DateTime.Parse("00:00:00")
Result: DateTime
11/4/2023 12:00:00 AM
11/4/2023 12:00:00 AM
Compile: 562.029ms | Execution: 41.161ms | React with ❌ to remove this embed.
MODiX
MODiX13mo ago
TheRanger
REPL Result: Failure
DateTime.Parse("")
DateTime.Parse("")
Exception: FormatException
- String '' was not recognized as a valid DateTime.
- String '' was not recognized as a valid DateTime.
Compile: 491.920ms | Execution: 30.205ms | React with ❌ to remove this embed.
Jarski
JarskiOP13mo ago
That looks like my error.
TheRanger
TheRanger13mo ago
yeah LastBackupTime seems to be empty was there a ' ' between String and was?
Jarski
JarskiOP13mo ago
Yeah. Looks to be the issue. I'll give it a go now and check.
Jarski
JarskiOP13mo ago
No description
Jarski
JarskiOP13mo ago
Changing it to 00:00:00 like the other one isn't the solution apparently. What format should I need to give this thing
TheRanger
TheRanger13mo ago
are u using DateTime.Parse or DateTime.ParseExact? and what do u expect the DateTime's value to be when it parses 00:00:00 ?
Jarski
JarskiOP13mo ago
I just manually set it properly to a random date and time. Turns out I needed the time too. Eg: "00:00:00 00:00:00" That part looks to be working now. If I have the program in the startup folder, will it autolaunch with admin privileges? Or should I need to add something to the code?
Chiyoko_S
Chiyoko_S13mo ago
I'd suggest you use ParseExact and specify the format you expect like HH:mm:ss, instead of letting Parse figure out which is user culture dependent no the app can't magically elevate itself on its own; additionally, an executing process cannot be elevated, instead it has to get started elevated tricks some apps use is to check if the process is elevated, then if not, start a new process that is elevated (through cmd command runas) though the best way is to explicitly specify your app requires elevated privilege through app manifest though, both solutions does not solve the problem that Windows will still regardless display UAC prompt when the application is run I think you should be able to use Task scheduler to register your app to be run on startup because you can configure the task to start up elevated that would probably happen on installation through the installer
Jarski
JarskiOP13mo ago
Task scheduler on startup. Gotcha. Will look into this later. Appreciate the help.
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server