String.Net “System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生
今天编写String.Net时,遇到“System.TypeInitializationException”类型的未经处理的异常在 Spring.NetDemo.exe 中发生
原因配置文件的顺序写错
原顺序:
1 <configuration> 2 <startup> 3 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 4 </startup> 5 6 <configSections> 7 <sectionGroup name="spring"> 8 <section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/> 9 <section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/> 10 </sectionGroup> 11 12 </configSections> 13 14 <spring> 15 <!--Spring.Net对象容器的配置--> 16 <context> 17 <!--容器里所有对象在哪里配置?--> 18 <resource uri="config://spring/objects"/> 19 </context> 20 21 <!--objects:配置的容器的里面的对象--> 22 <objects xmlns="http://www.springframework.net" > 23 <description>An example that demonstrates simple IoC features.</description> 24 <object name="UserInfoDal" type="Spring.NetDemo.UserInfoDal, Spring.NetDemo" singleton="false" > 25 26 </object> 27 </objects> 28 </spring> 29 30 31 </configuration>
改正后的顺序为:
1 <configSections> 2 <sectionGroup name="spring"> 3 <section name="context" type="Spring.Context.Support.ContextHandler,Spring.Core"/> 4 <section name="objects" type="Spring.Context.Support.DefaultSectionHandler,Spring.Core"/> 5 </sectionGroup> 6 7 </configSections> 8 9 <spring> 10 <!--Spring.Net对象容器的配置--> 11 <context> 12 <!--容器里所有对象在哪里配置?--> 13 <resource uri="config://spring/objects"/> 14 </context> 15 16 <!--objects:配置的容器的里面的对象--> 17 <objects xmlns="http://www.springframework.net" > 18 <description>An example that demonstrates simple IoC features.</description> 19 <object name="UserInfoDal" type="Spring.NetDemo.UserInfoDal, Spring.NetDemo" singleton="false" > 20 21 </object> 22 </objects> 23 </spring> 24 25 <startup> 26 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 27 </startup>