无法在自定义配置文件提供程序中加载类

Cra*_*gly 10 c# asp.net-profiles console-application

我在C#中编写一个小型控制台应用程序,它引用了一个实现自定义.net Profile提供程序的自定义程序集.我已将以下部分添加到我的app.config文件中,该文件引用了自定义类和程序集.

<system.web>
<profile defaultProvider="MyCompanyProfileProvider" inherits="MyCompany.Web.User.GenericProfile" automaticSaveEnabled="false">
    <providers>
        <clear/>
        <add name="MyCompanyProfileProvider" connectionStringName="defaultDatabase" applicationName="/myApplication" type="MyCompany.Web.ProfileProvider, MyCompany.Web"/>
    </providers>
    <properties>
        <add name="JobRoleId" type="System.Int32"/>
        <add name="LastCompetencyId" type="System.Int32" defaultValue="0"/>
        <add name="MixSettings" type="System.Xml.XmlDocument"/>
    </properties>
</profile></system.web>
Run Code Online (Sandbox Code Playgroud)

但是,当我在调试模式下运行应用程序时,我得到以下错误,就好像它正在查看System.Web程序集而不是app.config文件中指定的那个.

无法从程序集'System.Web,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'加载类型'MyCompany.Web.User.GenericProfile'.

我有一个本地Web应用程序,也使用程序集和自定义配置文件提供程序,并且没有任何问题.我已经检查了引用的程序集被复制到输出目录.

有任何想法吗??

Cra*_*gly 20

我终于找到了答案,这很简单!(他说经过几个小时的搜索和调试).

我只需要明确告诉我的自定义提供程序所在的程序集.我认为在添加提供程序时指定类型时我只需要执行此操作.

但是,您需要定义何时在inherits属性中定义配置文件.像这样:

之前:

<profile defaultProvider="MyCompanyProfileProvider"
         inherits="MyCompany.Web.User.GenericProfile"
         automaticSaveEnabled="false">
Run Code Online (Sandbox Code Playgroud)

后:

<profile defaultProvider="MyCompanyProfileProvider" 
         inherits="MyCompany.Web.User.GenericProfile, MyCompany.Web" 
         automaticSaveEnabled="false">
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助将来的其他人遇到同样的问题.