I had configuration warning in app.config of my wpf application.
my entire app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="schema URL">
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
I tried :
How to remove warning 'The 'configuration' element is not declared.' Visual Studio C#
and
The configuration element is not declared
and as stated in one of answers, tried to restart VS and start again. No luck
The configuration warning is gone, however the application can't start
Use this App.config file :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Related
My application runs only on .NET 2.0.
But, I had the following text in App.config in the deployed application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="assemblies"
type="Simple.Framework.AssembliesConfigurationSection, Simple.Framework"/>
</configSections>
<connectionStrings>
<add name="SystemSqlServer"
connectionString="Data Source=.\sqlexpress;Initial Catalog=gre;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
I replaced the supportedRuntime with the following text, as my application took a long time to start:
<supportedRuntime version="v2.0"
sku=".NETFramework,Version=v2.0"/>
But, I am getting the following message:
The following picture shows that .NET 2.0 is already installed:
and, my .net 3.5.1 is already turned on, and there is no additional option for .net 2.0.
I have recently tried Code Cop 1.3.1 - a method interceptor.
However won't run when .NET Framework 4.6 is installed.
The solution to this is to use the following runtime element set your app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<runtime>
<useLegacyJit enabled="1" />
</runtime>
</configuration>
I have this code to add some settings to the App.config in a WPF application. I thought it was a simple procedure, but in the end I couldn't save the setting to the file. Here is the code
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
settings.Add("server2", "http://someserver.com");
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
An here is the App.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<appSettings>
<add key="server1" value="someserver.net"/>
</appSettings>
</configuration>
What might be the problem?
Running the application from visual studio will create a new vshost.config every time. And so the settings are empty again.
The code is correct and settings will also be saved in config file.
Try running the .exe file from Debug/Release folder, the changes will be reflected.
When building my WPF application all internationalization/locale folders are put inside the folder of the executable.
/MyApp
/MyApp/de
/MyApp/fr
/MyApp/otherSpecialFolder
/MyApp/...
The problem is that this mixes up with some other folders. Is it possible to put the internationalization into a separate folder and let the Wpf app search there instead? For example:
/MyApp
/MyApp/i18n/de
/MyApp/i18n/fr
/MyApp/otherSpecialFolder
/MyApp/...
This problem occurs not only for own localization ressources but also when adding thirdparty controls like Xceed.Wpf.AvalonDock.
Yes you can. You just have to add probing element into your App.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="i18n"/>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
probing element specifies the path where assemblies are searched for.
I am using VS2012. I have to keep connection string in app.config and have to access it from my cs file. But I am unable to do it in VS2012. Following is what I have found from net but I think it works on earlier version of VS not on VS2012.
app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="DataFormConnection"
connectionString="Data Source=abcdd;database=xyz;uid=4566;pwd=987"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
How I am accessing it:
connectionString = ConfigurationManager.ConnectionStrings["DataFormConnection"].ConnectionString;
Getting error: type or name does not exist in System.Configuration.ConfiguarationSettings
Go to references, and add a reference to System.Configuration.
Go to References, and add a reference to System.Configuration
Once you have done this, you should be able to reference System.Configuration.ConfigurationManager.