Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load type in Custom Profile provider

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

like image 692
Cragly Avatar asked Apr 19 '10 08:04

Cragly


1 Answers

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.

like image 71
Cragly Avatar answered Oct 15 '22 23:10

Cragly