Sunday 05 September 2010

ProfileCommon is not defined – Problem Solved.

Back to Home 16 November 2009 by Raz

ProfileCommon is not defined - Problem Solved.

I was creating a new website based on code that I have created last year. I am sure many developers copy snippets of code to speed up the website construction phase. However when trying to access ProfileCommon from an external class it threw an error stating it wasn't defined.

Dim pfile As ProfileCommon = CType(HttpContext.Current.Profile, ProfileCommon)

ProfileCommon is not defined.

It worked great in code behind classes but not in an external class.

Why did it work before and not now?

 

I googled it and all the so called solutions involved recoding for ProfileBase which did help much. I had all this ready made code to work with the current profile and I didn't fancy all the re-coding.

I spent 4 hours debugging this issue and fell upon the answer. The problem was the fact that I was using a C# table profile provider and I typically write in VB. I had created a subdir in App_Code and put the C# files there, and created the mark-up to the subdir in Web.Config

<codeSubDirectories>

        <add directoryName="ProfileProvider"/>

</codeSubDirectories>

What gave the game away was that I noticed my Linq to SQL .dbml's were written in C# and not VB as selected. For some reason at rebuild time the first subdir parsed was the C# "ProvileProvider" dir, and VS decided to create C# objects from then on.

The fix was to delete all the C# objects and the C# subdir and rebuild the website, ProfileCommon access was restored. I re-created all my .dbml objects (in VB (which stuck this time)) and returned the ProfileProvider subdir with C# code .

Rebuilt the website and all is working as expected.

The problem is… I don't know why this fixed the problem or why the problem occurred.

Ideas gratefully received.


0 comment(s) for “ProfileCommon is not defined – Problem Solved.”


    What do you think?

    Name:  
    Email:
    (not shown)
     
    Website:  
    Comment:  
       

     

    Whilst we encourage your comments good and bad, all comments submitted are subject to our review and approval policy. Sorry, this is to cover our neck in case some nutter militant separatist mutant ninja turtle, uses this blog as a medium to spread jihad to all and sundry.

    Well…we can't have that can we.