2010-06-21 19 views
1

我已經加入了連接字符串到主可執行文件的App.config中我WPR,棱鏡應用程序,我得到以下錯誤:WPF和ADO.NET EF - 錯誤第二部分

System.TypeInitializationException was unhandled 
    Message=The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.Logger' threw an exception. 
    Source=Microsoft.Practices.EnterpriseLibrary.Logging 
    TypeName=Microsoft.Practices.EnterpriseLibrary.Logging.Logger 
    StackTrace: 
     at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() 
     at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message, ICollection`1 categories, Int32 priority, Int32 eventId, TraceEventType severity, String title, IDictionary`2 properties) 
     at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message, String category, Int32 priority) 
     at StockTraderRI.EnterpriseLibraryLoggerAdapter.Log(String message, Category category, Priority priority) in <my application>\EnterpriseLibraryLoggerAdapter.cs:line 28 
     at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration) in <my application>\CAL\Desktop\Composite.UnityExtensions\UnityBootstrapper.cs:line 85 
     at Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run() in <my application>\CAL\Desktop\Composite.UnityExtensions\UnityBootstrapper.cs:line 69 
     at StockTraderRI.App.RunInDebugMode() in <my application>\app.xaml.cs:line 44 
     at StockTraderRI.App.OnStartup(StartupEventArgs e) in <my application>\app.xaml.cs:line 34 
     at System.Windows.Application.<.ctor>b__1(Object unused) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.DispatcherOperation.InvokeImpl() 
     at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Windows.Threading.DispatcherOperation.Invoke() 
     at System.Windows.Threading.Dispatcher.ProcessQueue() 
     at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
     at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
     at System.Windows.Threading.Dispatcher.Run() 
     at System.Windows.Application.RunDispatcher(Object ignore) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run(Window window) 
     at System.Windows.Application.Run() 
     at StockTraderRI.App.Main() in <my application>\obj\Debug\App.g.cs:line 0 
    InnerException: System.Configuration.ConfigurationErrorsException 
     Message=Configuration system failed to initialize 
     Source=System.Configuration 
     BareMessage=Configuration system failed to initialize 
     Line=0 
     StackTrace: 
     InnerException: System.Configuration.ConfigurationErrorsException 
      Message=Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element. (<my application>\bin\Debug\StockTraderRI.exe.Config line 7) 
      Source=System.Configuration 
      BareMessage=Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element. 
      Filename=<my application>.exe.Config 
      Line=7 
      StackTrace: 
       at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) 
       at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) 
       at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() 
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) 

我的應用.conf看起來像這樣:

<?xml version="1.0"?> 
<configuration> 
    <connectionStrings> 
    <add name="DBEntities" connectionString="metadata=res://DataAccessLayer/EntityDataModel.csdl|res://DataAccessLayer/EntityDataModel.ssdl|res://DataAccessLayer/EntityDataModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\DB.sdf;Password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 

    <configSections> 

    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </configSections> 

有沒有人知道什麼是錯的?謝謝閱讀。

+0

還要注意 - 接受你的一些歷史的答案是在另一篇文章中提到 - 你需要點擊刻度來接受它作爲解決你的問題的答案。 – 2010-06-23 11:28:17

回答

4

內部異常很明顯地指向錯誤。你需要改變你的app.config看起來像這樣:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    </configSections> 
    <connectionStrings> 
    <add name="DBEntities" connectionString="metadata=res://DataAccessLayer/EntityDataModel.csdl|res://DataAccessLayer/EntityDataModel.ssdl|res://DataAccessLayer/EntityDataModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;Data Source=|DataDirectory|\DB.sdf;Password=password;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings>