我正在尝试访问 Windows 服务应用程序中 app.config 的自定义部分。

我是这样定义的

<Configurations> 
 <configSections> 
   <section name="SectionName" type="ClassName, AssemblyName"/> 
 </configSections> 
 <SectionName>...</SectionName> 
</Configurations> 

出现以下错误

An error occurred creating the configuration section handler for SectionName: Unable to load type 'ClassName, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it is not public.

此错误的可能原因是什么?

请您参考如下方法:

虽然该类存在并且可以公开访问,但它缺少默认构造函数。
显然,默认构造函数将在解析配置时在内部调用,因此对于此类类来说是必须的,它们在配置部分中使用。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!