This thread is 3 years old, but I wanted to share my experience anyway.
I had
- The same "Root element is missing" exception,
- Also after working fine for months,
- Once it started, rebooting didn't fix it.
This was on some Raspberry Pi modules (6 out of about 100), all running the same Raspberry OS build with the same build of an AspNetCore app (ARM build, self-contained).
What happened & how I solved it (in my case):
AspNetCore stores data protection keys (1 file per key) either in a default location, or in the location you set after the services.AddDataProtection()
call (your app may not have such a call, in that case the default is used).
The default in my case -- Linux -- was ~/.aspnet/DataProtection-Keys/ .
I found two xml files there, one of which was empty (size 0 bytes). Deleting the empty file and rebooting fixed the issue; a new file with another GUID in its name was automatically created at the next start.
The problem will probably be the same on Azure or Windows, you'll just have to find where it stores those files.
If you don't need the data protection, your app may not use it, but the runtime will use it anyway.
As far as I can tell, you can prevent the problem from recurring by saying you don't need permanent keys (but read the warning in the docs, encrypted data will become undecipherable once the app exits):
services.AddDataProtection().UseEphemeralDataProtectionProvider();
Possible cause
Judging by one discussion I found through Google, it could be that multithreaded apps that do not explicitly call AddDataProtection are susceptible to the problem, which would be the result of a race condition.
Personally, in my case, I believe it's more likely to be caused by powering off without a clean shutdown.