Spring.net 中的 CannotLoadObjectTypeException
我在 vs 2010 的 asp.net 3.5 项目中使用 spring.net 1.3.1。我需要 Spring 来创建和操作对象。
我遵循了文档,添加了 Spring.Core 和 Spring.Web dll 引用,我的 web.config 是这样的:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<system.web>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<!-- no spring confi in httpHandlers-->
</system.web>
<spring>
<context>
<resource uri="~/config/clients.xml" />
</context>
</spring>
client.xml 中
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="CAL" type="myrouter.clientcode.CAL, myrouter.clientcode"/>
</objects>
在Defaults.aspx.cs 的
IApplicationContext ctx = ContextRegistry.GetContext();
CAL calobject = (CAL)ctx.GetObject("CAL");
,我得到
[TypeLoadException:无法从字符串值“myrouter.clientcode.CAL,myrouter.clientcode”加载类型。] Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) 在 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolver.cs:81 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\GenericTypeResolver.cs:97 中的 Spring.Core.TypeResolution.GenericTypeResolver.Resolve(String typeName) c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\CachedTypeResolver.cs 中的 Spring.Core.TypeResolution.CachedTypeResolver.Resolve(String typeName):107 Spring.Core.TypeResolution.TypeResolutionUtils.ResolveType(String typeName) 在 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolutionUtils.cs:106 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinition.cs 中的 Spring.Objects.Factory.Support.AbstractObjectDefinition.ResolveObjectType() : 640 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support 中的 Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) \AbstractObjectFactory.cs:1096 [CannotLoadObjectTypeException: 无法解析文件 [D:\WORK\visual studio\Visual Studio 2010\Projects\myrouter\myrouter\config\clients.txt' 中定义的名称为“CAL”的对象的类型 [myrouter.clientcode.CAL、myrouter.clientcode]。 xml]第3行] c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support 中的 Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) \AbstractObjectFactory.cs:1100 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs 中的 Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() :第472章 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs 中的 Spring.Context.Support.AbstractApplicationContext.Refresh():1017 Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) 在 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:125 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context 中的 Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) \Support\WebApplicationContext.cs:82 _dynamic_Spring.Context.Support.WebApplicationContext..ctor(对象[])+242 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Reflection\Dynamic\DynamicConstructor.cs 中的 Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] 参数): 116 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs 中的 Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor):563 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs 中的 Spring.Context.Support.ContextInstantiator.InstantiateContext():508 Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContextparentContext,对象configContext,字符串contextName,类型contextType,布尔大小写敏感,字符串[]资源)在c:_svn \ spring-net \ tags \ spring-net-1.3.1 \ src中\Spring\Spring.Core\Context\Support\ContextHandler.cs:351 Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext父级,对象configContext,字符串contextName,类型contextType,布尔大小写敏感,String []资源)在c:_svn \ spring-net \ tags \ spring-net-1.3.1 \ src中\Spring\Spring.Web\Context\Support\WebContextHandler.cs:129 Spring.Context.Support.ContextHandler.Create(对象父级,对象configContext,XmlNode部分)在c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ ContextHandler.cs:289 [ConfigurationErrorsException:创建上下文“spring.root”时出错:无法从字符串值“myrouter.clientcode.CAL,myrouter.clientcode”加载类型。] System.Configuration.BaseConfigurationRecord.EvaluateOne(字符串[]键,SectionInput输入,布尔值isTrusted,FactoryRecordfactoryRecord,SectionRecordsectionRecord,对象parentResult)+202 System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecordfactoryRecord,SectionRecordsectionRecord,对象parentResult,布尔getLkg,布尔getRuntimeObject,对象和结果,对象和结果RuntimeObject)+1061 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey,布尔getLkg,布尔checkPermission,布尔getRuntimeObject,布尔requestIsHere,对象和结果,对象和结果RuntimeObject)+1431 System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey,布尔值getLkg,布尔值checkPermission)+56 System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +8 System.Web.HttpContext.GetSection(字符串节名称)+47 System.Web.Configuration.HttpConfigurationSystem.GetSection(字符串节名)+39 System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(字符串configKey)+6 System.Configuration.ConfigurationManager.GetSection(字符串节名)+78 Spring.Util.ConfigurationUtils.GetSection(字符串sectionName)在c:_svn \ spring-net \ tags \ spring-net-1.3.1 \ src \ Spring \ Spring.Core \ Util \ ConfigurationUtils.cs:71 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs 中的 Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath):335 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs 中的 Spring.Context.Support.WebApplicationContext.GetRootContext():223 c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebSupportModule.cs 中的 Spring.Context.Support.WebSupportModule.Init(HttpApplication 应用程序):175 System.Web.HttpApplication.InitModulesCommon() +65 System.Web.HttpApplication.InitModules() +43 System.Web.HttpApplication.InitInternal(HttpContext上下文,HttpApplicationState状态,MethodInfo[]处理程序)+729 System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext上下文)+298 System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext上下文)+107 系统.Web
抱歉这篇长文章;我希望尽可能准确并提供尽可能多的信息。我想我错过了一些东西,但就是不知道是什么。 HttpHandler是asp.net中spring.net配置中必须的吗?
I'm using spring.net 1.3.1 in a asp.net 3.5 project in vs 2010. I'm not doing any kind of mvc stuff; I needed Spring to create and manipulate objects.
I've followed the documentation, added Spring.Core and Spring.Web dlls reference my web.config is like this:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
<system.web>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>
<!-- no spring confi in httpHandlers-->
</system.web>
<spring>
<context>
<resource uri="~/config/clients.xml" />
</context>
</spring>
in clients.xml
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="CAL" type="myrouter.clientcode.CAL, myrouter.clientcode"/>
</objects>
in Defaults.aspx.cs
IApplicationContext ctx = ContextRegistry.GetContext();
CAL calobject = (CAL)ctx.GetObject("CAL");
i'm getting
[TypeLoadException: Could not load type from string value 'myrouter.clientcode.CAL, myrouter.clientcode'.]
Spring.Core.TypeResolution.TypeResolver.Resolve(String typeName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolver.cs:81
Spring.Core.TypeResolution.GenericTypeResolver.Resolve(String typeName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\GenericTypeResolver.cs:97
Spring.Core.TypeResolution.CachedTypeResolver.Resolve(String typeName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\CachedTypeResolver.cs:107
Spring.Core.TypeResolution.TypeResolutionUtils.ResolveType(String typeName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Core\TypeResolution\TypeResolutionUtils.cs:106
Spring.Objects.Factory.Support.AbstractObjectDefinition.ResolveObjectType() in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinition.cs:640
Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1096
[CannotLoadObjectTypeException: Cannot resolve type [myrouter.clientcode.CAL, myrouter.clientcode] for object with name 'CAL' defined in file [D:\WORK\visual studio\Visual Studio 2010\Projects\myrouter\myrouter\config\clients.xml] line 3]
Spring.Objects.Factory.Support.AbstractObjectFactory.ResolveObjectType(RootObjectDefinition rod, String objectName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectFactory.cs:1100
Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons() in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Objects\Factory\Support\DefaultListableObjectFactory.cs:472
Spring.Context.Support.AbstractApplicationContext.Refresh() in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:1017
Spring.Context.Support.WebApplicationContext..ctor(WebApplicationContextArgs args) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:125
Spring.Context.Support.WebApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:82
_dynamic_Spring.Context.Support.WebApplicationContext..ctor(Object[] ) +242
Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Reflection\Dynamic\DynamicConstructor.cs:116
Spring.Context.Support.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:563
Spring.Context.Support.ContextInstantiator.InstantiateContext() in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:508
Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:351
Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebContextHandler.cs:129
Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:289
[ConfigurationErrorsException: Error creating context 'spring.root': Could not load type from string value 'myrouter.clientcode.CAL, myrouter.clientcode'.]
System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +202
System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +1061
System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +1431
System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) +56
System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +8
System.Web.HttpContext.GetSection(String sectionName) +47
System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName) +39
System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) +6
System.Configuration.ConfigurationManager.GetSection(String sectionName) +78
Spring.Util.ConfigurationUtils.GetSection(String sectionName) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Core\Util\ConfigurationUtils.cs:71
Spring.Context.Support.WebApplicationContext.GetContextInternal(String virtualPath) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:335
Spring.Context.Support.WebApplicationContext.GetRootContext() in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebApplicationContext.cs:223
Spring.Context.Support.WebSupportModule.Init(HttpApplication app) in c:_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Web\Context\Support\WebSupportModule.cs:175
System.Web.HttpApplication.InitModulesCommon() +65
System.Web.HttpApplication.InitModules() +43
System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +729
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +298
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
System.Web
Sorry for this long post; I wanted to be as precised as possible and give as much as information that I could. I think I'm missing something but just can't figure out what. Is the HttpHandler
a must in spring.net configuration in asp.net?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常此问题是由于配置中的某些错误造成的
。
检查/验证以下内容:
Usually this issue is the result of some error in your
configuration.
Check/verify the following:
没关系,我已经修复了。我使用了错误的程序集信息。
Never mind, i got it fixed.i used the wrong assembly info.