Saturday, December 25, 2010

Code behind file not found

"If your code behind files are not compiling to dll then the problem could be codefile attribute, replace it with codebehind"
 
Hi All,

A few days back while working on a DNN module which is actually an extension to DNN core module Survey I faced a problem.

As this module's code comes in WSP version I copied C Sharp version of its code in DNN module template type visual studio project and then compiled it so as to get a DLL of its code. It got built after a few arrangements(like commenting a few lines :)

Then I copied the DLL to bin folder and tried to create module as per the procedure. It worked good all the way around till module creation. Then I added this newly created module to a page and BANG!!, here comes the error.

Error said,
type survey.ascx.cs not found

Note: survey.ascx is the view control of my module.

From the error message and placing code behind files in module folder I figured out that my module was able to get code in files like provider model classes and controller and info classes. It was just not getting the code-behind files of the ASCX controls used although it was able to pick codebehind code if if I place the code behind files in module's folder itself.

Thus problem became clear that something was stopping code behind files from compiling. So I compared my survey.ascx file with an old module's viewcontrol.ascx file and in the first line I got the culprit.

It was "codefile" attribute in ascx file's code directive line. I replaced it with codebehind and the problem was resolved.

So the moral of story is
if your code behind files are not compiling to dll then the problem could be codefile attribute, replace it with codebehind and enjoy!!!!!

No comments:

Post a Comment