Mistake
System.NullReferenceException: The object reference does not indicate an object instance. in FastFoodDemo.Program.GetConnection () in C: \ Users \ User \ Desktop \ FastFoodDemo \ FastFoodDemo \ Program.cs: line 36
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Reflection; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Configuration; using MySql.Data.MySqlClient; namespace FastFoodDemo { public class Program { /// <summary> /// The main entry point for the application. /// </summary> /// [STAThread] public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form2()); } public static int admin = 0; public static string server = "null"; public static MySqlConnection GetConnection() { MySqlConnection conn = new MySqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["connect_admin"].ConnectionString; return conn; } } } app.config
<connectionStrings> <add name="connect_admin" connectionString="Data Source=192.168.0.1;Initial Catalog=database;Persist Security Info=True;User ID=admin;Password=123" providerName="MySql.Data.MySqlClient" /> </connectionStrings> How to be gentlemen, tell me please) Given that when you start the program from VS 2017 - it works. But as soon as they launch the finished * .exe, this crashes :(
exename.exe.config- Artyom OkonechnikovConnectionStrings["connect_admin"]because this section is not in the configuration file, because there is no configuration file itself. Compile the application and open thebinfolder there will be your executable file and a number of the configuration file, so everything works for you "from the studio". You should do the same with your output file after ILMerge, put this configuration file next to it with the name in the format that I wrote in the comment above. - Artyom Okonechnikov