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

发布于 2024-08-29 01:23:54 字数 1188 浏览 1 评论 0原文

我正在用 C# 编写一个小型控制台应用程序,该应用程序引用实现自定义 .net 配置文件提供程序的自定义程序集。我已将以下部分添加到引用自定义类和程序集的 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>

但是,当我在调试模式下运行应用程序时,出现以下错误,就好像它在 System.Web 程序集中查找而不是在 app.config 文件中指定的错误一样。

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

有一个本地 Web 应用程序,它也使用程序集和自定义配置文件提供程序,并且可以正常工作。我已检查引用的程序集是否已复制到输出目录。

有什么想法吗?

I am writing a small console application in C# that references a custom assembly that implements custom .net Profile provider. I have added the following sections to my app.config file which references the custom class and assembly.

<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>

However when I run the app in debug mode I get the following error as if it is looking in the System.Web assembly rather than one specified in the app.config file.

Could not load type 'MyCompany.Web.User.GenericProfile' from assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I have a local web app that also uses the assembly and custom Profile provider and that work without any problems. I have checked the referenced assembly is being copied to the output directory.

Any ideas??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沫雨熙 2024-09-05 01:23:54

我终于找到了这个问题的答案,而且就是这么简单! (他在经过数小时的搜索和调试后说道)。

我只需明确说明我的自定义提供程序驻留在哪个程序集中。我认为我只需要在添加提供程序时指定类型时执行此操作。

但是,您需要在继承属性中定义配置文件时进行定义。像这样:

之前:

<profile defaultProvider="MyCompanyProfileProvider"
         inherits="MyCompany.Web.User.GenericProfile"
         automaticSaveEnabled="false">

之后:

<profile defaultProvider="MyCompanyProfileProvider" 
         inherits="MyCompany.Web.User.GenericProfile, MyCompany.Web" 
         automaticSaveEnabled="false">

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

I finally found the answer to this and it was so simple!! (He says after hours of searching and debugging).

I just had to tell explicitly say in which assembly my custom provider resided. I thought I only had to do this when specifying the type when adding the provider.

However you need to define when defining your profile in the inherits attribute. Like so:

Before:

<profile defaultProvider="MyCompanyProfileProvider"
         inherits="MyCompany.Web.User.GenericProfile"
         automaticSaveEnabled="false">

After:

<profile defaultProvider="MyCompanyProfileProvider" 
         inherits="MyCompany.Web.User.GenericProfile, MyCompany.Web" 
         automaticSaveEnabled="false">

Hope this helps somebody else in the future with the same problem.

够钟 2024-09-05 01:23:54

尝试删除指定类和程序集的逗号后面的额外空格,但我认为这不会解决问题。

您的应用程序正在 System.Web 程序集中查找您的自定义类,这非常奇怪。

我会使用 fuslogvw 获取更多详细信息关于失败。

Try removing the extra space behind the comma where you specify your class and assembly, but I don't think that will fix it.

Your app is looking up your custom class in the System.Web assembly, which is very strange.

I'd use fuslogvw to get more details on the failure.

原野 2024-09-05 01:23:54

在我浪费了几天宝贵的时间来解决这个问题之后,你的解决方案挽救了我的遗憾。像往常一样,我浪费了很多时间与微软的产品作斗争,而不是我需要自己解决的实际 IT 问题。我的 App.Config 行现在看起来是这样,并且似乎工作正常:

<profile defaultProvider="DefaultProfileProvider" inherits="SmartTariffs_V13.ProfileCommon, SmartTariffs_V13">
  <providers>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  </providers>
</profile>

其中 SmartTariffs_V13 是项目的名称,SmartTariffs_V13.ProfileCommon 是该项目中 .cs 文件的名称。我发现这无需添加“automaticSaveEnabled”标签即可工作,但是嘿嘿...

Your solution saved my sorry a*se after I WASTED DAYS of my precious time chasing down this problem. As usual, I have WASTED DAYS fighting Microsoft's products instead of the actual IT problems I need to solve themselves. My App.Config lines now look thus and it seems to work fine:

<profile defaultProvider="DefaultProfileProvider" inherits="SmartTariffs_V13.ProfileCommon, SmartTariffs_V13">
  <providers>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  </providers>
</profile>

Where SmartTariffs_V13 is the name of the Project and SmartTariffs_V13.ProfileCommon is the name of the .cs file within that project. I found this works without adding your "automaticSaveEnabled" tag, but hey ho ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文