无法从控制台应用程序(和 mstest)使用 Azure TableStorageMembershipProvider

发布于 2024-10-19 20:49:45 字数 1074 浏览 4 评论 0原文

在我正在构建的 Web 应用程序中,我使用 TableStorageMembershipProvider 示例代码(从 此处)用于用户管理。我已经正确设置了 web.config,一切正常。

我现在想要编写一些测试,因此我创建一个测试项目,引用 TableStorageMembershipProvider dll,将相关部分从 web.config 复制到 app.config 并编写一个简单的测试。问题是,我第一次点击会员代码时,它会抛出以下错误:

Could not load type 'Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

它正在尝试从 System.Web 加载 TableStorageMembershipProvider...

因此,我创建了两个单独的项目 - 一个控制台应用程序和一个新的 MVC3 Web 应用程序 - 两者其中简单地引用了TableStorageMembershipProvider dll。我使用指定成员资格提供程序的相同条目设置 web.config 和 app.config 并编写一行代码:

Membership.ApplicationName = "test";

MVC 应用程序工作,控制台应用程序抛出与上面相同的错误。

我尝试在控制台应用程序中复制所有 Web 应用程序引用并将所有内容设置为 Copy Local = true - 没有成功。为这个而撕心裂肺...

VS2010,所有项目都针对.Net 4

必须有一个真正简单的解决方案吗?

In a web app I'm building I'm using the TableStorageMembershipProvider sample code (downloaded from here) for user management. I've setup the web.config correctly and everything works just fine.

I now want to write some tests, so I create a test project, reference the TableStorageMembershipProvider dll, copy the relevant sections from web.config to app.config and write one simple test. Problem is that the first time I hit the membership code, it throws the following error:

Could not load type 'Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

It's trying to load the TableStorageMembershipProvider from System.Web...

So I then create two separate projects - a console app and a new MVC3 web app - both of which simply reference the TableStorageMembershipProvider dll. I setup the web.config and app.config with the same entries which specify the membership provider and write one line of code:

Membership.ApplicationName = "test";

The MVC app works, the console app throws the same error as above.

I've tried duplicating all web app references in the console app and setting all to Copy Local = true - no luck. Tearing my bloody hair out over this...

VS2010, all projects target .Net 4

There's got to be a real simple solution?

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

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

发布评论

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

评论(3

晨曦慕雪 2024-10-26 20:49:45

默认情况下,控制台应用程序没有对 System.Web 的引用,而 MVC 应用程序有。我想您会发现收到的错误消息有点误导。我认为正在发生的事情是 TableStorageMembershipProviderSystem.Web 的依赖,无论出于何种原因,它都不会流向您的控制台应用程序。

尝试将对 System.Web 的引用添加到您的控制台应用程序中,这应该可以修复它。

By default console apps don't have a reference to System.Web, MVC apps do. I think you'll find that the error message you're getting is a little misleading. What I think is happening is that TableStorageMembershipProvider has a dependency on System.Web that for whatever reason isn't flowing through to your console app.

Trying adding a reference to System.Web to your console app and that should fix it.

西瑶 2024-10-26 20:49:45

要检查的事项:

  1. 您是否使用“.NET 4 Framework”或
    “.NET 4 Framework 客户端配置文件”中
    你的控制台应用程序?它应该
    成为第一。
  2. 你有 Azure 程序集吗
    小路?

Things to check:

  1. Are you using ".NET 4 Framework" or
    ".NET 4 Framework Client Profile" in
    your Console application? It should
    be the first.
  2. Have you the Azure assemblies in you
    path?
深海里的那抹蓝 2024-10-26 20:49:45

您的配置似乎设置为从 System.Web 加载类,而不是您的类所在的程序集。您可以从控制台应用程序发布配置(如果您仍然遇到此问题)吗?

It looks like your config is set to load the class from System.Web rather than the assembly that your class is in. Can you post the config (if you're still having this problem) from your console app?

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