App wont run when adding 'appSettings' to config file

M

moondaddy

I'm running a wpf windows app and want to add the appSettings element to the
config file. when I do, the app wont start up and I get the following
error:

{"The type initializer for 'System.Windows.Application' threw an
exception."}
{"The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw
an exception."}
" at System.Windows.Application..ctor()\r\n at
DiagramTool_v1.App..ctor()\r\n at DiagramTool_v1.App.Main() in
D:\\nwis\\Apps\\WPF\\DiagramTool_v1\\DiagramTool_v1\\obj\\Debug\\App.g.cs:line
0\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at
System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

the app will run when the config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>


But not like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>

Note: this DID work in a .net 1.1 app. Am I supposed to put the
appSettings element somewhere else now? Isnt there a tool I can use to
create config files through a windows UI?

Thanks.
 
V

VJ

Did not do it for me. I just created a Windows application in C# had a Form,
with one button and to show a messagebox in the button click event. I add
the information you gave to the config file, it opened ok!

keep a break point at Application.Run and debug. Is not even going beyond
it?

VJ
 
R

RobinS

He's doing WPF. YOu have to create a WPF Windows Application to test out
what he's doing.

moondaddy -- how are you adding the info to the config file? Are you using
C# or VB?

Robin S.
--------------------------------
VJ said:
Did not do it for me. I just created a Windows application in C# had a
Form, with one button and to show a messagebox in the button click event.
I add the information you gave to the config file, it opened ok!

keep a break point at Application.Run and debug. Is not even going beyond
it?

VJ

moondaddy said:
I'm running a wpf windows app and want to add the appSettings element to
the config file. when I do, the app wont start up and I get the
following error:

{"The type initializer for 'System.Windows.Application' threw an
exception."}
{"The type initializer for 'System.Windows.Navigation.BaseUriHelper'
threw an exception."}
" at System.Windows.Application..ctor()\r\n at
DiagramTool_v1.App..ctor()\r\n at DiagramTool_v1.App.Main() in
D:\\nwis\\Apps\\WPF\\DiagramTool_v1\\DiagramTool_v1\\obj\\Debug\\App.g.cs:line
0\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

the app will run when the config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>


But not like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>

Note: this DID work in a .net 1.1 app. Am I supposed to put the
appSettings element somewhere else now? Isnt there a tool I can use to
create config files through a windows UI?

Thanks.
 
V

VJ

Ahh WPF.. never gone there yet.. You will get better response from WPF
specific group..

VJ
 
R

RobinS

The problem is there isn't one, per se. There's
microsoft.public.windows.developer.winfx.avalon, but it doesn't have a lot
of traffic.

Other than that, there is the MSDN forum for WPF. I think this guy has the
support option from MS, though, because eventually they will answer his
question. In order for that to happen, he has to post it to one of the
managed newsgroups, of which this is one.

Robin S.
-----------------------------
VJ said:
Ahh WPF.. never gone there yet.. You will get better response from WPF
specific group..

VJ
moondaddy said:
I'm running a wpf windows app and want to add the appSettings element to
the config file. when I do, the app wont start up and I get the
following error:

{"The type initializer for 'System.Windows.Application' threw an
exception."}
{"The type initializer for 'System.Windows.Navigation.BaseUriHelper'
threw an exception."}
" at System.Windows.Application..ctor()\r\n at
DiagramTool_v1.App..ctor()\r\n at DiagramTool_v1.App.Main() in
D:\\nwis\\Apps\\WPF\\DiagramTool_v1\\DiagramTool_v1\\obj\\Debug\\App.g.cs:line
0\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

the app will run when the config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>


But not like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>

Note: this DID work in a .net 1.1 app. Am I supposed to put the
appSettings element somewhere else now? Isnt there a tool I can use to
create config files through a windows UI?

Thanks.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Regarding on the WPF application, normally adding AppSetting keys should
not affect your application's runtime behavior. From the error message you
posted, the problem seems occur at type's initialize time. If possible,
would you post some detailed code snippet (you can try creating a
simplified project which can repro the same error behavior) so that we can
perform some further investigation on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

moondaddy

Thanks to all who have been responding.

1) Yes I get support from MS here so I post WPF questions here rather than
the MSND forums (although I go there some as well).

2) Here's the code from the app.config file where I'm having my trouble:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add
name="DiagramTools.Properties.Settings.DiagramToolConnectionString"
connectionString="xxxxxxxxxxxxxxxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

and when I remove this code all works fine:

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

does this shed any light?


RobinS said:
The problem is there isn't one, per se. There's
microsoft.public.windows.developer.winfx.avalon, but it doesn't have a lot
of traffic.

Other than that, there is the MSDN forum for WPF. I think this guy has the
support option from MS, though, because eventually they will answer his
question. In order for that to happen, he has to post it to one of the
managed newsgroups, of which this is one.

Robin S.
-----------------------------
VJ said:
Ahh WPF.. never gone there yet.. You will get better response from WPF
specific group..

VJ
moondaddy said:
I'm running a wpf windows app and want to add the appSettings element to
the config file. when I do, the app wont start up and I get the
following error:

{"The type initializer for 'System.Windows.Application' threw an
exception."}
{"The type initializer for 'System.Windows.Navigation.BaseUriHelper'
threw an exception."}
" at System.Windows.Application..ctor()\r\n at
DiagramTool_v1.App..ctor()\r\n at DiagramTool_v1.App.Main() in
D:\\nwis\\Apps\\WPF\\DiagramTool_v1\\DiagramTool_v1\\obj\\Debug\\App.g.cs:line
0\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)\r\n at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n at
System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n at
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

the app will run when the config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>


But not like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>

Note: this DID work in a .net 1.1 app. Am I supposed to put the
appSettings element somewhere else now? Isnt there a tool I can use to
create config files through a windows UI?

Thanks.
 
M

moondaddy

I found the problem. my solution has many projects and one of them also had
an app config file which also had an appSettings element in it. this
created a conflict when I added another appSettings element to a different
project.


moondaddy said:
Thanks to all who have been responding.

1) Yes I get support from MS here so I post WPF questions here rather
than the MSND forums (although I go there some as well).

2) Here's the code from the app.config file where I'm having my trouble:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add
name="DiagramTools.Properties.Settings.DiagramToolConnectionString"
connectionString="xxxxxxxxxxxxxxxxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

and when I remove this code all works fine:

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

does this shed any light?


RobinS said:
The problem is there isn't one, per se. There's
microsoft.public.windows.developer.winfx.avalon, but it doesn't have a
lot of traffic.

Other than that, there is the MSDN forum for WPF. I think this guy has
the support option from MS, though, because eventually they will answer
his question. In order for that to happen, he has to post it to one of
the managed newsgroups, of which this is one.

Robin S.
-----------------------------
VJ said:
Ahh WPF.. never gone there yet.. You will get better response from WPF
specific group..

VJ
I'm running a wpf windows app and want to add the appSettings element
to the config file. when I do, the app wont start up and I get the
following error:

{"The type initializer for 'System.Windows.Application' threw an
exception."}
{"The type initializer for 'System.Windows.Navigation.BaseUriHelper'
threw an exception."}
" at System.Windows.Application..ctor()\r\n at
DiagramTool_v1.App..ctor()\r\n at DiagramTool_v1.App.Main() in
D:\\nwis\\Apps\\WPF\\DiagramTool_v1\\DiagramTool_v1\\obj\\Debug\\App.g.cs:line
0\r\n at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)\r\n at System.AppDomain.ExecuteAssembly(String
assemblyFile, Evidence assemblySecurity, String[] args)\r\n at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)\r\n at
System.Threading.ThreadHelper.ThreadStart()"

the app will run when the config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>


But not like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="RunFrom" value="Voyager" />
</appSettings>

<configSections>
</configSections>
<connectionStrings>
<add name="some string...." />
</connectionStrings>
</configuration>

Note: this DID work in a .net 1.1 app. Am I supposed to put the
appSettings element somewhere else now? Isnt there a tool I can use to
create config files through a windows UI?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

editing a config file 2
log4net in console app 2
dll config issue... 1
app config file 2
Separate .config file 3
config file changes 2
writing to config file 3
config file dosn't work when I deploy my app 2

Top