Custom Configuration Sections

前端 未结 5 2424
暖寄归人
暖寄归人 2021-02-20 14:34

I am currently trying to implement a Custom Configuration Section in a project I am busy with and no matter what I try I keep getting the error below:

{\"An error occurr

相关标签:
5条回答
  • 2021-02-20 14:35

    My guess is that you've copied the code, but you have different assembly names. Posting the config will help.

    I would also fully quality your type in the config (something that sample doesn't show). Something like...

    <section name="MySection" type="My.Assembly.Type, My.Assembly" />
    
    0 讨论(0)
  • 2021-02-20 14:45

    So it turns out that when you create a project in Visual Studio, it automatically defines a root namespace (the name of the project by default) for the project. Thus you must include that root namespace in the section type as well as any custom namespaces you defined within your settings class.

    For example, in the case of the original poster a working configuration for them may have looked something like this:

    <section name="MySection" type="ROOT_NAMESPACE.Samples.AspNet.PageAppearanceSection, NAME_OF_ASSEMBLY" />
    

    Where ROOT_NAMESPACE and NAME_OF_ASSEMBLY are defined in the project properties as shown in this snapshot of my project.

    assembly name and root namespace visual studio

    In my particular case, I did not explicitly define namespaces in my project. Thus my section configuration setting just had the root namespace, the name of the settings class, and the name of the assembly, as such;

    <section name="programSettings" type="ShipmentImport.ProgramSettings, ShipmentImport" />    
    

    I know its a couple years late, but I hope it keeps somebody else from spending hours on this like I did.

    0 讨论(0)
  • 2021-02-20 14:49

    You should also check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.

    • Unraveling the mysteries of .NET 2.0 configuration
    • Decoding the mysteries of .NET 2.0 configuration
    • Cracking the mysteries of .NET 2.0 configuration

    Highly recommended, well written and extremely helpful!

    Marc

    0 讨论(0)
  • 2021-02-20 14:59

    Please try with the following code:

    <configSections>
        <sectionGroup name="pageAppearanceGroup">
             <section name="pageAppearance" type="Samples.AspNet.PageAppearanceSection,Samples.AspNet" allowLocation="true"         allowDefinition="Everywhere"       />
        </sectionGroup>     <!-- Other <section> and <sectionGroup> elements. -->
    </configSections>  
    
    0 讨论(0)
  • 2021-02-20 14:59

    Please try with this

    <configSections>
     <sectionGroup name="pageAppearanceGroup">
      <section name="pageAppearance"
               type="Samples.AspNet.PageAppearanceSection,Samples.AspNet"
               allowLocation="true"
               allowDefinition="Everywhere" />
     </sectionGroup>
     <!-- Other <section> and <sectionGroup> elements. -->
    </configSections>  
    

    Thanks, Vedi

    0 讨论(0)
提交回复
热议问题