今天编写String.Net时,遇到“System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生

原因配置文件的顺序写错

原顺序:

 <configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup> <configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/>
</sectionGroup> </configSections> <spring>
<!--Spring.Net对象容器的配置-->
<context>
<!--容器里所有对象在哪里配置?-->
<resource uri="config://spring/objects"/>
</context> <!--objects:配置的容器的里面的对象-->
<objects xmlns="http://www.springframework.net" >
<description>An example that demonstrates simple IoC features.</description>
<object name="UserInfoDal" type="Spring.NetDemo.UserInfoDal, Spring.NetDemo" singleton="false" > </object>
</objects>
</spring> </configuration>

改正后的顺序为:

  <configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/>
</sectionGroup> </configSections> <spring>
<!--Spring.Net对象容器的配置-->
<context>
<!--容器里所有对象在哪里配置?-->
<resource uri="config://spring/objects"/>
</context> <!--objects:配置的容器的里面的对象-->
<objects xmlns="http://www.springframework.net" >
<description>An example that demonstrates simple IoC features.</description>
<object name="UserInfoDal" type="Spring.NetDemo.UserInfoDal, Spring.NetDemo" singleton="false" > </object>
</objects>
</spring> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
05-08 15:13