为什么在使用Spring.net加载ASPX页面时会出现NullReferenceException?

时间:2012-04-25 17:42:08

标签: asp.net asp.net-4.0 spring.net

我正在尝试使用Spring.net 1.3.2设置ASP.Net 4网站。

对于基本页面,Spring会毫无问题地加载页面并注入依赖项。 但是在某些页面上,我在ctor和Page_Load之间得到一个NullReferenceException,其中包含以下信息:

消息:

Value cannot be null.
Parameter name: methodInfoDeclaration

堆栈追踪:

   at System.Reflection.Emit.TypeBuilder.DefineMethodOverrideNoLock(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)
   at System.Reflection.Emit.TypeBuilder.DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)
   at Spring.Proxy.AbstractProxyMethodBuilder.BuildProxyMethod(MethodInfo method, MethodInfo interfaceMethod) in c:\_prj\spring-net\trunk\src\Spring\Spring.Core\Proxy\AbstractProxyMethodBuilder.cs:line 107
   at Spring.Web.Support.SupportsWebDependencyInjectionTypeBuilder.BuildProxyType()
   at Spring.Web.Support.InterceptControlCollectionStrategy.GetInterceptedCollectionType(Type controlCollectionType, InjectDependenciesCallbackHandler staticCallback)
   at Spring.Web.Support.InterceptControlCollectionStrategy.GetInterceptedCollectionFactory(Type ownerType, Type collectionType)
   at Spring.Web.Support.InterceptControlCollectionStrategy.InterceptCollection(Control owner, ControlCollection originalCollection)
   at Spring.Web.Support.InterceptControlCollectionStrategy.Intercept(IApplicationContext defaultApplicationContext, ControlAccessor ctlAccessor, ControlCollectionAccessor ctlColAccessor)

在一个页面上,我将其缩小为SiteMapDataSource的问题,一旦我发表评论,该异常就会消失。但是例外情况仍会出现在其他页面上。

我在别处找到了类似错误的人:http://forum.springframework.net/showthread.php?6621-Spring.NET-ASP.NET-4.0-Error

然而,版本1.3.1中已修复相关错误。

以下是我的Web.config的相关部分:

<sectionGroup name="spring">
  <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup>

[...]

<httpHandlers>
  <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
</httpHandlers>

<httpModules>
  <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
</httpModules>

我的对象定义:

<object type="Default.aspx">
    <property name="TestProperty" value="Spring injected" />
</object>

有人可以告诉我如何避免这种异常吗?

1 个答案:

答案 0 :(得分:1)

两个Spring程序集之间的版本不匹配。我的一位同事通过NuGet引用了Spring.Core,而我通过手动下载的发行版引用了Spring.Web。

引用来自同一来源的两个程序集解决了这个问题。