2009-08-03 12 views
5

मेरी WPF आवेदन (समग्र आवेदन) में मैं App.config फ़ाइल में एक चर संग्रहीत करना चाहते हैं, लेकिन जैसे ही मैं एक appSettings App.config में खंड जोड़ने के रूप में, यह मुझे इस त्रुटि देता है:App.config में ** appSettings ** अनुभाग क्यों जोड़ना WPF अनुप्रयोग में त्रुटि का कारण बनता है?

The type initializer for System.Windows.Application threw an exception.

app.config:

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
     <appSettings> 
      <add key="SmartFormMockDirectory" value="C:\test"/> 
     </appSettings> 
    <configSections> 
    </configSections> 
    <system.serviceModel> 
     <bindings> 
     <basicHttpBinding> 
      <binding name="Service1Soap" closeTimeout="00:01:00" openTimeout="00:01:00" 
      receiveTime... 

सामान्य तौर पर मैं इस काम करता है since I can get it to work in simple applications like this पता है।

उपरोक्त त्रुटि का कारण क्या हो सकता है और मैं इसे कैसे ठीक कर सकता हूं ताकि मैं App.config फ़ाइल में चर जोड़ सकूं?

+0

प्रकार प्रारंभकर्ता अपवादों के साथ, आप कोशिश करते हैं और एक InnerException के लिए पूछताछ करना चाहिए। आमतौर पर एक है। इस मामले में यह आपको एक बेहतर जवाब दिया होगा। हालांकि, एंड्रयू बहुत सही है। –

उत्तर

25

ऐसा लगता है कि आपने <configSections> नोड से ऊपर <appSettings> नोड रखा है। फ़ाइल में पहला तत्व होने या इसे हटाने के लिए या तो <configSections> नोड को शीर्ष पर ले जाएं (जैसा कि आप इसका उपयोग नहीं कर रहे हैं)।

configSections Element से:

If the configSections element is in a configuration file, the configSections element must be the first child element of the configuration element.

+0

अच्छा काम ...... – Jinesh

+0

। + 1, आपने इसे खींचा .. – tariq

+0

यह मुझे पागल कर रहा था! कॉन्फ़िगरेशन को पहले तत्व के रूप में रखते हुए लगभग को हल किया गया। –

संबंधित मुद्दे