RickStrahl / Westwind.ApplicationConfiguration

Strongly typed, code-first configuration classes for .NET applications
http://west-wind.com/westwind.applicationconfiguration/
178 stars 36 forks source link

Suggestion: do not call Write() in a Read() method. #5

Closed huanlin closed 10 years ago

huanlin commented 10 years ago

I had a very weird situation that whenever I access my web application, it starts and shutdown immediately and normally without any exception. After some tests, I eventually find out that's because ConfigurationFileConfigurationProvider is writing to web.config every time in the Read() method. I can see that from the web.config file's time stamp. But I didn't call any Write() method in my application code.

Then I remove Westwind.ApplicationConfiguration assembly from my projects and write my own configuration class. Problem solved. Today I try to reproduce it with a simple program and submit a bug to here, but I couldn't reproduce it!

Now you might be thinking that the problem must lies in my application code. But before I can reproduce it, I would suggest that we do not call Write() in a Read() method because it's implicit and not clear. Or at least provide a Boolean property to explicitly control this manner, such as CreateConfigItemIfNotExist or AutoCreateConfigItems. Just a suggestion.

Thank you for reading this.

huanlin commented 10 years ago

I just reproduced it! If I download the latest source code from GitHub and compile it. There is no problem with this version. That's why I could reproduce it before. This version of Westwind.Utilities.Configuration.dll is 2.20.1.0.

If I use NuGet Manager to add the assembly reference to my projects, the bug shows again. This version of Westwind.Utilities.Configuration.dll is 2.20.0.0.

So I think the version download from NuGet has this bug.

RickStrahl commented 10 years ago

Thanks for the report. I'll update the NuGet package. This bug was fixed a couple of months ago thanks to feed back from another user here.

huanlin commented 10 years ago

That's great! Thank you Rick!

RickStrahl commented 10 years ago

Package has been updated. Thanks for your feedback!