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 开发者_StackOverflow社区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?
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.
Things to check:
- Are you using ".NET 4 Framework" or ".NET 4 Framework Client Profile" in your Console application? It should be the first.
- Have you the Azure assemblies in you path?
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?
精彩评论