Error while generating a file: Invalid argument: value in Settings.settings - c#

The compiler tells me:
Error while generating a file: Invalid argument: value in Settings.settings
And when I click this error, it opens up the Settings.settings file.
Does anybody see anything wrong in here?
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>

I could resolve this by adding a Custom Tool Namespace.

Related

How to stop config file from throwing errors because of symbols? [duplicate]

Following config file causes error because of & in 'url' value:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="url" value ="http://www.example.com/?user=admin&password=1234"/>
</appSettings>
</configuration>
The question is which encoding to use for key/value in a config file ? (i.e Url Encoding ...)
This is an XML file. As such, you must XML-escape all reserved characters:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="url" value ="http://www.example.com/?user=admin&password=1234"/>
</appSettings>
</configuration>
Programmatically you can perform this type of escaping using the System.Web.HttpUtility.HtmlEncode method. Yes, its name suggests HTML specific encoding, but in my experience this is equivalent to XML escaping.

Problem calling a second .config for keys in C#

I need a second .config to manage alot of keys. I tried using
<configSections>
<section name="apiConnection" type="CustomConfig.apiConnectionSection, CustomConfig" />
</configSections>
<apiConnection configSource ="ApiConnection.config"/>
Where "ApiConnection.config" is my .config file to manage keys but this didn't work.
Then i tried the "file" property in appSettings.
<appSettings file="ApiConnection.config">
This didn't work either. I Tried with:
../ApiConnection.config
~/ApiConnection.config
But nothing...
Some ideas?
The program doesnt break, just not show me the keys when i try with the ConfigurationManager.
https://i.stack.imgur.com/6xHK2.png
<img src= https://i.stack.imgur.com/6xHK2.png/>
EDIT
My file is in root path (with web.config)
The file looks like
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="Secret" value="z8xyHkN3Eju2TS9u-4MXeI2AbZiuTsF7xYJcjIJ" />
<add key="Audience" value="keyforms"/>
</appSettings>
Ok I think I know what your problem is based on your last comment.
This code is creating a new configuration section called apiConnection.
<configSections>
<section name="apiConnection" type="CustomConfig.apiConnectionSection, CustomConfig" />
</configSections>
<apiConnection configSource ="ApiConnection.config"/>
This section's values will not be contained in app settings. So you won't be able to access it via
ConfigurationManager.AppSettings
You will need to access it in a different manner. Now the exact manner will depend on your implementation of CustomConfig.apiConnectionSection and CustomConfig. I would search your code to find the class that defines how this works.
This example shows how to pull values from a custom config section, SecureAppSettings that uses the NameValueCollection in the same manner as AppSettings. You will have to do some digging to figure out what Types you will need to utilize.
NameValueCollection section = (NameValueCollection)ConfigurationManager.GetSection("secureAppSettings");
string userName = section["userName"];

Sitecore 8.2, Adding a ComputedIndexField to Solr configuration

I need to add a ComputedIndexField to my Solr Configuration
Doing so by creating a config patch containing the following
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration>
<fields hint="raw:AddComputedIndexField">
<field fieldName="SomeFieldName">
Type, Dll
</field>
</fields>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
But i kept getting the error. Even though this was the format the documentation was suggesting.
Could not find property 'fieldMap' on object of type: System.String
The problem:
The naming of my custom config was making it load before the nodes that it was trying to patch. I fixed it by changing the name so that they would load AFTER the node.

Reading from a app.config file

I am trying to print to Console.Write the value of the key name from the following app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="name" value="Chan" />
</appSettings>
</configuration>
C# code :
Console.Write(ConfigurationManager.AppSettings["name"]);
Nothing gets printed in the console. Why is this ?
Note: I have added a reference to the System.Configuration dll
below code gives you the content of active config file.
var content = File.ReadAllLines(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Check what you get as content, is it contain key="name" value="Chan" or something else
?
if you given <add key="name" value="Chan" /> then
ConfigurationManager.AppSettings["name"] should return as Chan
Given that your XML file (app.config) is properly formatted, try below.
Declare a variable and assign the variable the AppSettings value. Similar like-
string sName = "";
sName = ConfigurationManager.AppSettings["name"].ToString();

Enterprise Library Section Error

Everytime when I open my Solution that is using the Enterprise Library from Microsoft I get this error after building or opening my app.config.
After this Message my Visual Studio is shutting down ! My Configuration hasn't changed for a year and I only got this error just since a few days. I don't know where it comes from and why VS is shutting down after this Message ...
Anyone knows this error maybe ?
My Config looks like this :
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=....." />
</configSections>
<enterpriselibrary.configurationSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" applicationName="...." xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="dataConfiguration" encrypt="true">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="......" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:type="FileKeyAlgorithmPairStorageProviderData" name="File Key Algorithm Storage Provider" path="....">
<dpapiSettings xsi:nil="true" />
</keyAlgorithmStorageProvider>
<includeTypes />
</enterpriselibrary.configurationSettings>
Inserting the configsections into the machine.config solved the problem. Unfortunately I don't understand the reason ...

Categories

Resources