From 130a05be7ba65484a4a7a078c86063e1c4854ca8 Mon Sep 17 00:00:00 2001
From: Daniel Grunwald <daniel@danielgrunwald.de>
Date: Fri, 5 Nov 2010 12:30:57 +0100
Subject: [PATCH] Fixed http://community.sharpdevelop.net/forums/t/12147.aspx -
 <configSections> must be first element in app.config

---
 src/Main/Base/Project/Src/Project/CompilableProject.cs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/Main/Base/Project/Src/Project/CompilableProject.cs b/src/Main/Base/Project/Src/Project/CompilableProject.cs
index cb86f2a782..a9e5753d5e 100644
--- a/src/Main/Base/Project/Src/Project/CompilableProject.cs
+++ b/src/Main/Base/Project/Src/Project/CompilableProject.cs
@@ -612,7 +612,12 @@ namespace ICSharpCode.SharpDevelop.Project
 					XElement startup = configuration.Element("startup");
 					if (startup == null) {
 						startup = new XElement("startup");
-						configuration.AddFirst(startup);
+						if (configuration.HasElements && configuration.Elements().First().Name == "configSections") {
+							// <configSections> must be first element
+							configuration.Elements().First().AddAfterSelf(startup);
+						} else {
+							configuration.AddFirst(startup);
+						}
 					}
 					XElement supportedRuntime = startup.Element("supportedRuntime");
 					if (supportedRuntime == null) {