Application settings error after changing target framework of project

老子叫甜甜 提交于 2019-12-10 12:40:08

问题


In my application I am using user settings as explained here. Then I realized that in VS 2010 I was using .NET 4.0 while only .NET 2.0 was sufficient.

When I changed the framework and build the project, in my code whenever I access setting now, I get the following error:

An error occurred creating the configuration section handler for userSettings/Vegi_Manager.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:\Users\AKSHAY\AppData\Local\Microsoft\Vegi-Manager.vshost.exe_Url_44035dlkzpfaaauiqsd4nh3f0l0yq0tv\1.0.0.0\user.config line 5)

It is for unknown reasons using version 4.0. Please suggest what should I do.


回答1:


Check out your app.config maybe you still have System.Configuration.UserSettingsGroup or something of that sort of version 4 still lurking around, you will have to manually edit and get the relevant for version 2




回答2:


I was having the same problem having started developing my Outlook add-in in Visual Studio 2010 targeting the .NET 4.0 framework and then deciding to change it to the 3.5 framework. It seems Visual Studio was NOT smart enough to update my app.config file which still had a reference to 4.0.

As previous posters have suggested (I'll be just a little bit more specific), by manually editing app.config to change all references from "Version=4.0.0.0" to "Version=2.0.0.0" (apparently .NET 3.5 still uses 2.0.0.0) in the <sectionGroup> element and its child elements, I was able to get the settings working again in my case.




回答3:


It is likely that you have a reference to a .NET 4 assembly in your solution - if you open the "Add Reference" window in your solution and make the window a bit wider, you will see that there are columns for Version and Runtime... when you created your solutions to target .NET 4, you might have added a reference to an assembly that requires the .NET 4 runtime and now you have changed to .NET 2, you need to swap it for an assembly that only needs the .NET 2 runtime.

Of course, if you have used something form the .NET 4 assembly that didn't exist in .NET 2, you will either have to re-write to avoid using it or change your mind and do it in .NET 4 instead!




回答4:


if you open your app.config, make sure all the config sections are targeting .net framework 2 not 4

if you post your app.config to me i can help more




回答5:


May I add here that you need to change the app.config details / references to the previous .NET framework (in this case 4.0.0.0) to the new System refence .NET version (in this case 2.0.0.0 which is the same for .NET 3.5!)



来源:https://stackoverflow.com/questions/6408308/application-settings-error-after-changing-target-framework-of-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!