One of my users is getting a
System.Configuration.ConfigurationErrorsException when my Windows
Forms application tries to encrypt and save the application config
file, but it only happens for him and no other users!? I don't really
know anything about the security classes so don't have any idea where
to start looking, but would love some suggestions.

He gets the exception when running the application on other users'
machines for whom it works fine, and other users are able to log in on
his machine and use the application. So I'm guessing it's something
to do with his profile but I have no idea where to look. He and all
other users have the same .NET version; I installed it as part of the
application install and noone had previous .NET runtimes on their
machine.

In my live application I get a standard windows box saying the program
had a problem and had to be closed, do I want to send info to MS.
(That's despite having set a ThreadException handler which normally
logs and shows a message for all unhandled exceptions, which is
slightly odd in itself.)

I created a test app to determine where it's failing, and it crashes
in this method:

The info in the standard .NET exception handler is at the bottom of
this post.

In my test app he is able to save the config file fine without
encryption, using this code:
private void btnSaveConfig_Click(object sender, EventArgs e)
{
// Same stuff as ProtectConfiguration, but without the
protection.
// Checks if we can open and save the config file.
Configuration config = null;
config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.ConnectionStrings;
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
MessageBox.Show("ok");
}

He's also able to do RSA encryption and decryption using the
RSACryptoServiceProvider class; I included in my test app the sample
code here:
http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider(VS.80).aspx

If anyone can suggest why this exception could be occurring and why
it's attached to just this user I'd greatly appreciate it!

fyi the reason I'm doing this is that during application install my
application opens and encrypts the config file so connection details
can't be read by the casual observer. Not perfect security but good
enough, providing it runs!

Share This Page

Welcome to PC Review!

Hello and welcome to PC Review. We're a friendly computing community, bustling with knowledgeable members to help solve your tech questions.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask any tech support questions, or chat with the community and help others.
Sign up now!