❔ "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
which line throws that error and what is the value of the string?
Is the string ISO8601?
no idea, i reference datetime strings a couple times.
trying to find where it actually saves the properties.
heres the properties:
wrap ur xml like this
```xml
// your xml
```
apologies, using wrong key
i mean visual studio can tell you which line throws the error and you can debug its value
It's not throwing the error on visual studio.
It works just fine running as a build from vs
i assume its trying to parse this?
00:00:00
TheRanger
REPL Result: Success
Result: DateTime
Compile: 562.029ms | Execution: 41.161ms | React with ❌ to remove this embed.
TheRanger
REPL Result: Failure
Exception: FormatException
Compile: 491.920ms | Execution: 30.205ms | React with ❌ to remove this embed.
That looks like my error.
yeah LastBackupTime seems to be empty
was there a
' '
between String
and was
?Yeah. Looks to be the issue. I'll give it a go now and check.
Changing it to 00:00:00 like the other one isn't the solution apparently. What format should I need to give this thing
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 ?
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?
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 installerTask scheduler on startup. Gotcha. Will look into this later. Appreciate the help.
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.