Reputation: 3616
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??
Upvotes: 10
Views: 4182
Reputation: 3616
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.
Upvotes: 20
Reputation: 107
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 ...
Upvotes: 0
Reputation: 22368
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.
Upvotes: 0