Azure, MVC Core Web App suddenly throw "XmlException: Root element is missing" + "CryptographicException"

506 views Asked by At

I have a web application hosted by an Azure App service. It has worked fine for years but suddenly I get an Exception when i try to enter the Account/login action: -->"XmlException: Root element is missing" + "CryptographicException: An error occurred while trying to encrypt the provided data.". If i got to Home/About action (which have [AllowAnonymous] attribute) that page works fine. But if i try to enter a page within the Account controller which have the [AllowAnonymous] attribute. That also throw the same Exception. So I am guessing the Exception occur in the constructor for the Account controller. See below.

I have not made any updates to the page in months and it has worked fine until now. If I run the application locally on my PC (connected to the same database on azure) it works fine. As I understand Azure have recently made updates to their portal. My guess is that the cause of the error is related to that.

Does anyone know how to solve this?

public AccountController(
        UserManager<ApplicationUser> userManager,
        SignInManager<ApplicationUser> signInManager,
        IEmailSender emailSender,
        ILogger<AccountController> logger,
        ApplicationDbContext context)
    {
        _userManager = userManager;
        _signInManager = signInManager;
        _emailSender = emailSender;
        _logger = logger;
        _context = context;
    }
1

There are 1 answers

0
Fredrik Ling On

Ok so I found the problem myself. After digging in to Debug snapshots available in Azure i got a hint that the directory where the app was trying to get the xml causing the exception was "D:\home\ASP.NET\DataProtection-Keys". When I analysed the content of that directory I saw that one xml-file was empty. I Deleted that file. And that solved the problem.