Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试使用XYZ pcmsim=(XYZ)appConfig.GetSection(“XYZ”)获取节时出错;_C#_Config - Fatal编程技术网

C# 尝试使用XYZ pcmsim=(XYZ)appConfig.GetSection(“XYZ”)获取节时出错;

C# 尝试使用XYZ pcmsim=(XYZ)appConfig.GetSection(“XYZ”)获取节时出错;,c#,config,C#,Config,需要解释以下MSDN链接上的配置节类型 对以下章节有异议 <configuration> <configSections> <section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample" allowDefinition="Everywhere" allow

需要解释以下MSDN链接上的配置节类型

对以下章节有异议

    <configuration>
      <configSections>
        <section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample" 
          allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" 
          restartOnExternalChanges="true" />
      </configSections>
      <CustomSection fileName="override.txt" alias="alias.txt" 
        maxUsers="1000" maxIdleTime="00:05:00" />
    </configuration>


节名称有一个类型。我需要知道逗号前后的名称应该使用什么。我打开了解决方案资源管理器并查看了程序集的引用。我假设引用和类型必须匹配。我的应用程序和许多嵌套类以及MSDN网页没有提供有关如何在嵌套类中引用对象的良好信息。

类型
属性指定的值表示
CustomSection类型的程序集限定名

类型的程序集限定名由类型名组成, 包括其名称空间,后跟逗号,后跟显示 程序集的名称

ConfigurationPropertyExample.CustomSection,ConfigurationPropertyExample
从左到右包括

  • 命名空间:
    ConfigurationPropertyExample
  • 类型/类名:
    CustomSection
  • 包含
    CustomType
    类型:
    ConfigurationPropertyExample

    (大多数情况下,这将是不带(.dll或.exe)文件扩展名的程序集文件名。)

  • 使用
    Type.AssemblyQualifiedName
    属性检索类型程序集限定名

    var assemblyQualifiedName = typeof(CustomSection).AssemblyQualifiedName;
    
    返回的值可能不仅仅包括名称空间、类和程序集,
    如版本、区域性和公钥令牌(请参阅),例如

    ConfigurationPropertyExample.CustomSection,ConfigurationPropertyExample,版本=1.0.0.0,区域性=中性,PublicKeyToken=null

    大多数情况下,不必在配置
    类型
    定义中包含最后这些,除非您正在使用


    对于嵌套类,程序集限定名称中的嵌套类前面将有一个加号(
    +

    var assemblyQualifiedName = typeof(CustomSection).AssemblyQualifiedName;
    
    如果将
    CustomSection
    类定义为类
    Settings
    的嵌套类,则其程序集限定名称将为
    ConfigurationPropertyExample.Settings+CustomSection,ConfigurationPropertyExample

    namespace ConfigurationPropertyExample
    {
        public class Settings
        {  
            public sealed class CustomSection : ConfigurationSection
            {
                // ...
            }       
        } 
    }