locked
Cannot Load Custom Config File Section Handler Within A Custom Visual Studio 2010 Add-in RRS feed

  • Question

  • Hello,

     

    I’m trying to develop a simple Visual Studio 2010 add-in.

     

    Part of its implementation needs to read config file information.  The config file is NOT the application config file; it’s located in a different folder with a different name.

     

    Part of the config file uses a custom section handler.

     

    When I run the code, I receive:

     

    System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for Werk.MyAddin1.MyConfig: Could not load file or assembly 'Werk.MyAddin1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db53f0cc7935e07a' or one of its dependencies. The system cannot find the file specified. (C:\config.xml line 3) --

     

    Here’s  the config file (line 3 is the section element):

     

    <configuration>

      <configSections>

        <section name="Werk.MyAddin1.MyConfig" type="Werk.MyAddin1.MyConfig, Werk.MyAddin1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db53f0cc7935e07a" requirePermission="false" />

      </configSections>

      <Werk.MyAddin1.MyConfig>

      </Werk.MyAddin1.MyConfig>

    </configuration>

     

    Here’s simple code to reproduce the error (you can run it in the connect event or exec event):

     

    string ConfigFilePath = @"C:\config.xml";

     

    System.Configuration.ExeConfigurationFileMap pConfigFile = new System.Configuration.ExeConfigurationFileMap();

     

    pConfigFile.ExeConfigFilename = ConfigFilePath;

     

    System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(pConfigFile, System.Configuration.ConfigurationUserLevel.None);

     

    config.GetSection("Werk.MyAddin1.MyConfig");

     

    FYI: I can load the default section handler (System.Configuration.ClientSettingsSection) in the add-in, no problem, just not the custom handler.

     

    FYI: the above code will work fine in its own exe app, just not as a VS-2010 add-in.

     

    Any ideas?  I was thinking some security restriction for add-ins.

     

    Thanks in advance.

    Saturday, March 26, 2011 5:25 AM

Answers

  • Answered my own question. The assembly containing the custom handler needs to be visible to the VS-2010 AppDomain (either in the .exe folder or GAC or linkedConfiguration or some other redirection). Since the assembly containing the custom handler was the same as the add-in, it was located in a project subfolder, not visible to the VS process, even though the add-in itself was visible to VS by the .AddIn config file.

     

    Thanks

     

    • Marked as answer by coeholbrook Saturday, March 26, 2011 5:53 AM
    Saturday, March 26, 2011 5:53 AM

All replies

  • Answered my own question. The assembly containing the custom handler needs to be visible to the VS-2010 AppDomain (either in the .exe folder or GAC or linkedConfiguration or some other redirection). Since the assembly containing the custom handler was the same as the add-in, it was located in a project subfolder, not visible to the VS process, even though the add-in itself was visible to VS by the .AddIn config file.

     

    Thanks

     

    • Marked as answer by coeholbrook Saturday, March 26, 2011 5:53 AM
    Saturday, March 26, 2011 5:53 AM
  • Cheers, I'm glad it is resolved.

    :)


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 31, 2011 8:32 AM