我正在創建一個使用NHibernate和Spring.Net框架的程序。當我執行的應用程序,然後我得到以下異常無法從字符串值加載類型
錯誤創建上下文「spring.root」:無法加載從字符串值「BlackOpsP2.Data.EmployeeDao,BlackOpsP2.Data」類型。
這裏我有配置文件。
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
<sectionGroup name="spring">
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data"/>
</parsers>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.net/tx"
xmlns:db="http://www.springframework.net/database">
<db:provider id="DbProvider"
provider="SqlServer-2.0"
connectionString="Data Source=CHETUIWK123\SQL2008R2;Integrated Security=true;Database=TestNhibernate;"/>
<object id="MySessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate33">
<property name="ExposeTransactionAwareSessionFactory" value="true" />
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>BlackOpsP2.Core</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="dialect"
value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
</dictionary>
</property>
</object>
<object id="HibernateTransactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate33">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
<object id="EmployeeDao" xsi:schemaLocation="" type="BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
<object id="EmployeeService" type="BlackOpsP2.Services.ARModule.EmployeeService, BlackOpsP2.Services">
<property name="TransactionManager" ref="HibernateTransactionManager"/>
<property name="Dao" ref="EmployeeDao"/>
</object>
<object id="EmployeeController" type="BlackOpsP2.Presentation.Controller.ARModule.EmployeeController, BlackOpsP2.Presentation">
<property name="Service" ref="EmployeeService"/>
</object>
<!--> manually added -->
<object id="Form" type="BlackOpsP2.UI.Form1, BlackOpsP2.UI">
<property name="Controller" ref="EmployeeController"/>
</object>
<!--> /****/ -->
<tx:attribute-driven transaction-manager="HibernateTransactionManager"/>
</objects>
</spring>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender,log4net">
<file value="E:\Test\log.txt"/>
<appendToFile value="true"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO"/>
<levelMax value="FATAL"/>
</filter>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
</configuration>
我已經實現了以下目錄結構。
- ABC.Core
- ABC.Data
- ABC.Presentation
- ABC.Services
- ABC.UI
我經歷很多環節上了計算器,通過谷歌,但無法找到解決我的問題的相關信息。
我不知道爲什麼這個異常即將到來,我不知道如何解決它。我認爲這與輸出目錄有關,或者彈簧框架無法找到dll。
這裏我給出了一個詳細的跟蹤異常,我得到了。
System.Configuration.ConfigurationErrorsException was unhandled Message=Error creating context 'spring.root': Could not load type from string value 'BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data'. Source=System.Configuration BareMessage=Error creating context 'spring.root': Could not load type from string value 'BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data'. Line=0 StackTrace: at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Spring.Util.ConfigurationUtils.GetSection(String sectionName) at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded() at Spring.Context.Support.ContextRegistry.GetContext() at BlackOpsP2.UI.Program.Main() in E:\Project\BlackOps-P2\BlackOpsP2.UI\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(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.Threading.ThreadHelper.ThreadStart() InnerException: Spring.Core.CannotLoadObjectTypeException Message=Cannot resolve type [BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data] for object with name 'EmployeeDao' defined in config [E:\Project\Bin\BlackOps-P2\BlackOpsP2.UI\BlackOpsP2.UI.vshost.exe.Config#spring/objects] line 1 Source=Spring.Core ObjectName=EmployeeDao ObjectTypeName=BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data ResourceDescription=config [E:\Project\Bin\BlackOps-P2\BlackOpsP2.UI\BlackOpsP2.UI.vshost.exe.Config#spring/objects] line 1 StackTrace: at Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) at Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() at Spring.Context.Support.AbstractApplicationContext.Refresh() at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args) at Spring.Context.Support.XmlApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) at _dynamic_Spring.Context.Support.XmlApplicationContext..ctor(Object[]) at Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) at Spring.Context.Support.ContextHandler.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) at Spring.Context.Support.ContextHandler.ContextInstantiator.InstantiateContext() at Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, IList`1 resources) at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) InnerException: System.TypeLoadException Message=Could not load type from string value 'BlackOpsP2.Data.EmployeeDao, BlackOpsP2.Data'. Source=Spring.Core TypeName="" StackTrace: at Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) at Spring.Core.TypeResolution.GenericTypeResolver.Resolve(String typeName) at Spring.Core.TypeResolution.CachedTypeResolver.Resolve(String typeName) at Spring.Core.TypeResolution.TypeResolutionUtils.ResolveType(String typeName) at Spring.Objects.Factory.Support.AbstractObjectDefinition.ResolveObjectType() at Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) InnerException:
[更新]
當我已經加入下列中的app.config線然後錯誤消息改變。
<property name="MappingAssemblies">
<list>
<value>BlackOpsP2.Core</value>
<value>BlackOpsP2.Data</value>
</list>
</property>
和錯誤消息,這我得到
錯誤創建上下文「spring.root」:無法加載文件或程序集「BlackOpsP2.Data」或它的一個依賴。該系統找不到指定的文件。
是任何身體知道爲什麼它正在發生..
牆壁以便閱讀器38 SO讀者死亡。 – JYelton
看起來像它找不到類型BlackOpsP2.Data.EmployeeDao或程序集BlackOpsP2.Data – Maxim
我知道它但我不知道如何給它 – Awadhendra