Similar problem with NameValueSectionHandler
Hi All,
I'm migrating a perfectly working app from .Net 1.1 to .Net 2.0 b2 and I'm having very hard time to understand why I'm getting the following exception:
"An error occurred creating the configuration section handler for ColumnMappings: Could not load type 'SingleTagSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (C:\Documents and Settings\...\MyApp.EXE.config line 5)"
line of code where the exception occurs:IDictionary
mappingTable = (IDictionary) System.Configuration.ConfigurationManager.GetSection("ColumnMappings");
section of the .config file:<
configuration>
<configSections>
<sectionname="ColumnMappings"
type="System.Configuration.SingleTagSectionHandler"/>
Of course, this used to work perfectly with .Net 1.1 and the
IDictionary mappingTable = (IDictionary) ConfigurationSettings.GetConfig("ColumnMappings");code.
Any help is greatly appreciated !
Thank you.
[2220 byte] By [
Pejvan] at [2007-12-16]
That's because the it is trying to load the SingleTagSectionHandler from the System.Configuration assembly. However it actually exists in System.
Change the type attribute to:
type="System.Configuration.SingleTagSectionHandler, System";
Thank you very much for your help. You are totally right about the type, which is located into the System assembly. Is this a mistake from MS to have moved it from System.Configuration.dll to System.dll ?
Anyway, now the issue is even worse since I get the following exeption:
"An error occurred creating the configuration section handler for ColumnMappings: Could not load file or assembly 'System' or one of its dependencies. The system cannot find the file specified."
And now, I'm totally lost, :-(
For info, here's the line of the config file:
<section name="ColumnMappings" type="System.Configuration.SingleTagSectionHandler, System"/>
Thanks a lot.
No. It has always been located in the System.dll. In fact, System.Configuration didn't exist until .NET 2.0.
Okay, Microsoft must have changed the way they load types from configuration file (which is a breaking change).
I suggest that you first post a bug report on Microsoft Product Feedback Center and then try this in the meantime:
<section name="ColumnMappings" type="System.Configuration.SingleTagSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Thank you very much for your help, it indeed solved my issue.
I have now filled a bug report about this.
One more newbie/silly question: I can't find a way to get the PublicKeyToken of an assembly. Is there any easy way to obtain it? What about from within VS 2005b2?
Kind regards.
Probably the easiest way to find the PublicKeyToken of an assembly is by starting "Visual Studio 2005 Command Prompt" and running "gacutil -l <yourassembly>" from the command line. This will work for all the framework assemblies that are installed by default in the global assembly cache, which sounds like what you need.
Hope this helps!
By the way, the breaking change has been reverted in post-Beta2 builds of v2.0. You would most likely not have to make any updates to your config files if upgrading to 1.1 to 2.0 RTM, when available.
Thanks for both your messages.
As far as the breaking change is concerned, MS has did his job: make me waste 2 days trying to find a solution, which hopefully I did thanks to you guys!
I guess that's the way it is when you work with MS technologies :-)
and nothing can change this...
I have a similar problem with NameValueSectionHandler.
The program throws an exception pointing to the following line in the configuration file:
<
section name="Locations" type="System.Configuration.NameValueSectionHandler" />The exception says:
"Could not load type 'System.Configuration.NameValueSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
The solution mentioned here above did not help.
Any other ideas?
THank you,
Gennady.
I found a workaround for it: if I copy system.dll to the directory where the binary (.exe) resides, it works. It is enough to set the "Copy Local" property in the VS project and it does the job.
Gennady,
That is a not a valid workaround. Copying system .NET Framework dlls locally is a bad idea and will only cause problems in the long run.
To fix this simply do the same thing as the correct answer above.
Dear Pejvan,
I am doing exactly the same thing, but the following code always returns null:
IDictionary mappingTable = (IDictionary) ConfigurationSettings.GetConfig("ColumnMappings");
Any idea?
Cheers,
M.Mousavi
Hi Mehdi,
I have been doing the same thing that your are doing and I am getting 'Nothing' as return (equivalent of null in c#).
Did you find a solution or work around and can you please share it with me.
Thanks
SreeAtPru
Hi Mehdi,
Thank you for your feedback. In my case, I was able to figure out the problem. I have created the Myapp.exe.config from notepad, which has the configuration sections, however, my app.config did not have those sections and when added the sections to my app.config file, the problem resolved.
Thanks
Sree