Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App.config - encrypted section error:

I have an application that encrypts a section in the configuration file. In the first time that I try to read the encrypted section from the config file I get an error message: "Unrecognized attribute 'configProtectionProvider'. Note that attribute names are case-sensitive. "

config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
// Get the section in the file.   
ConfigurationSection section = config.GetSection("EncryptedSection");


if (section != null)      
{           
    // Protect the section.
    section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
    section.SectionInformation.ForceSave = true;

    // Save the change.

    config.Save(ConfigurationSaveMode.Modified);  
}  
ConfigurationManager.RefreshSection("EncryptedSection");  
Properties.Settings.Default.Reset();

//This is the part where I read the encrypted section:

ConfigurationManager.RefreshSection("EncryptedSection");
System.Collections.IDictionary HSMMasterKeyConfig = (System.Collections.IDictionary)System.Configuration.ConfigurationManager.GetSection("EncryptedSection");

This only happens in the first time that I try to read the encrypted section. I have noticed that the .config file is getting updated immediately after the first save but from some reason I need to restart the application in order to use the encrypted section.

like image 851
Joe Avatar asked Mar 23 '09 03:03

Joe


1 Answers

Have you read through this...

http://bytes.com/groups/net/521818-configurationerrorexception-when-reading-protected-config-section

... as it appears to be a conversation involving an MSFT support engineer that directly maps to your situation.

like image 76
Martin Peck Avatar answered Sep 28 '22 00:09

Martin Peck