我已将连接字符串添加到我的wpr,prism应用程序中主可执行文件的App.config中,并且出现以下错误:
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)
我的App.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="Data Source=|DataDirectory|\DB.sdf;Password=password;Persist Security Info=True"" 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 :(得分: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="Data Source=|DataDirectory|\DB.sdf;Password=password;Persist Security Info=True"" providerName="System.Data.EntityClient" />
</connectionStrings>