2016-08-09 3 views
0

Я пытаюсь создать свой собственный пользовательский раздел конфигурации со следующим:Не удалось загрузить файл или сборку при попытке создать пользовательский раздел конфигурации в веб-конфигурации

код в файле web.config:

<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <section name="customConfigurationSection" type="CustomConfigurationSectionRepro.ConfigHandlers.CustomConfigurationSection" allowLocation="true" allowDefinition="Everywhere" /> 
    </configSections> 

<customConfigurationSection fileName="\Configs\customconfig.config" /> 
.... 
.... 
</configuration> 

код в пользовательском файле конфигурации обработчика:

namespace CustomConfigurationSectionRepro.ConfigHandlers 
{ 
    public class CustomConfigurationSection : ConfigurationSection 
    { 
     [ConfigurationProperty("fileName", IsRequired = false)] 
     public string FileName 
     { 
      get 
      { 
       return (string)this["fileName"]; 
      } 
      set 
      { 
       this["fileName"] = value; 
      } 
     } 
    } 
} 

Мой веб-приложение является только стандартный MVC веб-приложение из Visual Studio шаблон MCV. Когда я запускаю его в среде разработки с помощью IIS Express, я продолжаю говорить об ошибке.

Could not load file or assembly 'CustomConfigurationSectionRepro' or one of its dependencies. An attempt was made to load a program with an incorrect format. 

=== Pre-bind state information === 
LOG: DisplayName = CustomConfigurationSectionRepro 
(Partial) 
WRN: Partial binding information was supplied for an assembly: 
WRN: Assembly Name: CustomConfigurationSectionRepro | Domain ID: 2 
WRN: A partial bind occurs when only part of the assembly display name is provided. 
WRN: This might result in the binder loading an incorrect assembly. 
WRN: It is recommended to provide a fully specified textual identity for the assembly, 
WRN: that consists of the simple name, version, culture, and public key token. 
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more  information and common solutions to this issue. 
LOG: Appbase = file:///C:/Users/vtran/Documents/Visual Studio 2015/Projects/Playground/CustomConfigurationSectionRepro/ 
LOG: Initial PrivatePath = C:\Users\vtran\Documents\Visual Studio 2015\Projects\Playground\CustomConfigurationSectionRepro\bin 
Calling assembly : (Unknown). 

Я искал вокруг, но не смог найти решение. Имена пространства имен и сборки кажутся правильными. Файл CustomConfigurationSectionRepro.dll также существует в папке bin.

Любая помощь была бы действительно оценена.

UPDATE: Если я сменил хост-сервер с IIS Express на локальный IIS, приложение получилось просто отлично. Я до сих пор не понимаю, почему.

ответ

0

Я думаю, что это должно быть в форме

<section name="customConfigurationSection" type="CustomConfigurationSectionRepro.ConfigHandlers.CustomConfigurationSection, CustomConfigurationSectionRepro" allowLocation="true" allowDefinition="Everywhere" /> 

используя запятую и имя DLL после имени класса.

+0

Я попытался, но все еще не работает :( – stoney78us

0

Похоже, что запись configSection в вашем web.config должна быть квалифицированной.

<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <section name="customConfigurationSection" type="CustomConfigurationSectionRepro.ConfigHandlers.CustomConfigurationSection" allowLocation="true" allowDefinition="Everywhere" /> 
    </configSections> 

Линия для type должна иметь узел, указанный с запятой и сборочного имя после того, как имя типа, как так:

CustomConfigurationSectionRepro.ConfigHandlers.CustomConfigurationSection, CustomConfigurationSectionRepro 

Оформление элемента конфигурации выглядеть следующим образом:

<section name="customConfigurationSection" type="CustomConfigurationSectionRepro.ConfigHandlers.CustomConfigurationSection, CustomConfigurationSectionRepro" allowLocation="true" allowDefinition="Everywhere" /> 
+0

Я попытался, но все же получил ту же ошибку :(. – stoney78us

Смежные вопросы