How to use custom sections in app.config from t4 template

I am trying to access a custom section in the app.config file from the t4 template in VS2010, but the assembly that defines the user section cannot be loaded.

I use ConfigurationAccessor to get the section (ref http://skysanders.net/subtext/archive/2010/01/23/accessing-app.configweb.config-from-t4-template.aspx ).

app.config:

<configSections>
    <section name="MyProviders" type="System.Web.Security.MySection, MyAssembly" />
</configSections>

<MyProviders default="SQLMyProvider">
  <providers>
    <add name="SQLMyProvider" ... connectionStringName="MyConnectionString" />
  </providers>
</MyProviders>

Call this line in a .tt file:

MySection section = (MySection)config.Configuration.GetSection("MyProviders");

Gives this error:

Conversion start: System.Configuration.ConfigurationErrorsException: An error occurred while creating the configuration section handler for MyProviders: Failed to load file or assembly "MyAssembly" or one of its dependencies. The system cannot find the specified file.

.tt , , . MySection tt, app.config.

?

+3
2

, <configSections> (, , )

type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
+1

MyAssembly GAC Visual Studios PublicAssemblies, . - <install_dir>\Common7\IDE\PublicAssemblies.

0

Source: https://habr.com/ru/post/1787653/


All Articles