C# DataContractSerializer-配置系统未能初始化--应用程序配置设置
我使用DataContractSerializer作为一个独立的部分来序列化一些使用DataContract/Member的对象。。。不幸的是,如果我在解决方案的配置设置中添加了一个与此过程完全无关的自定义App.Config部分,它会一直引发异常。。。例如,我的配置设置如下:C# DataContractSerializer-配置系统未能初始化--应用程序配置设置,c#,.net,serialization,datacontractserializer,datacontract,C#,.net,Serialization,Datacontractserializer,Datacontract,我使用DataContractSerializer作为一个独立的部分来序列化一些使用DataContract/Member的对象。。。不幸的是,如果我在解决方案的配置设置中添加了一个与此过程完全无关的自定义App.Config部分,它会一直引发异常。。。例如,我的配置设置如下: <configuration> <appSettings> <!--stuff goes here --> </appSettings>
<configuration>
<appSettings>
<!--stuff goes here -->
</appSettings>
<MyCustomSectionItDoesntLike>
<!--stuff goes here -->
</MyCustomSectionItDoesntLike>
</configuration>
如果我从配置设置中删除MyCustomSectionItDoesntLike,它工作正常,但当我将其放回时,会触发异常:
信息:
的类型初始值设定项
“System.Runtime.Serialization.DiagnosticUtility”引发异常
内部:
无法识别的配置节MyCustomSectionItDoesntLike。
(D:\test\bin\x86\Debug\test.vshost.exe.config第47行)
我不确定为什么它不关心项目中任何地方的设置,除非我要序列化。。。我是否需要添加设置或配置部分才能正常工作
谢谢
更新
总骨头错误。。。。与序列化程序无关
<configuration>
<configSections>
<!--This is where i blew it -->
<section name="MyCustomSectionItDoesntLike" type="System.Stuff.Stuff" />
</configSections>
<appSettings>
<!--stuff goes here -->
</appSettings>
<MyCustomSectionItDoesntLike>
<!--stuff goes here -->
</MyCustomSectionItDoesntLike>
</configuration>
您必须在app.config文件的
configSections
中引用实现自定义节的类
查看更多信息。不确定您的意思,这段代码不使用配置部分。。。项目的另一部分是这样的,它可以访问它……但是这个部分是在
configSections
中声明的吗?正如您所指出的,我完全错过了“configSections”部分。。。
<configuration>
<configSections>
<!--This is where i blew it -->
<section name="MyCustomSectionItDoesntLike" type="System.Stuff.Stuff" />
</configSections>
<appSettings>
<!--stuff goes here -->
</appSettings>
<MyCustomSectionItDoesntLike>
<!--stuff goes here -->
</MyCustomSectionItDoesntLike>
</configuration>