Je sais qu'une question similaire a été posée plus d'une fois. J'ai lu certaines réponses mais je n'ai pas trouvé de réponse claire à mon problème. Au point, je deux applications dire A & B. App A a un fichier de configuration comme suit:C# Comment modifier le fichier de configuration d'une autre application et enregistrer la modification?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key = "Key0" value = "4567" />
<add key = "Key1" value = "1" />
<add key = "Key2" value = "2" />
</appSettings>
</configuration>
App B tente de modifier "Key0" de l'App Un fichier de configuration:
namespace ModifyOtherConfig
{
public partial class Form1 : Form
{
string otherConfigFilePath;
public Form1()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"c:\users\om606\documents\visual studio 2015\projects\csharptesting\csharptesting\bin\debug\csharptesting.exe";
Configuration otherConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
string otherSetting = otherConfig.AppSettings.Settings["Key0"].Value;
MessageBox.Show(otherSetting);
otherSetting = "098";
MessageBox.Show(otherSetting);
otherConfig.SaveAs(fileMap.ExeConfigFilename, ConfigurationSaveMode.Full);
}
}
}
Lorsque J'essaie d'exécuter ce code, je reçois l'erreur suivante:
Une exception non gérée du type « System.Configuration.ConfigurationErrorsException » est produite dans System.Configuration.dll informations complémentaires: les données au ro Le niveau est invalide. Ligne 1, position 1.
Qu'est-ce que je fais de mal? Est-ce que je manque quelque chose de très évident? J'apprécierais que quelqu'un puisse me diriger dans la bonne direction.
Il semblerait que le fichier ne contienne pas de fichier XML approprié – Jonesopolis