NullReferenceExceptions objects creating new module

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/16/2011 3:04:55 AM
Gravatar
Total Posts 20
ScalSan

NullReferenceExceptions objects creating new module

Hi guys,

I am creating a Module that accepts some numbers and verifies them after submission, as a test to get going with the fantastic MojoPortal framework...

To simplify things and be able to learn, I followed the video tutorials and used the Guestbook tutorial files which made me create the different layers and classes, MSSQL database and scripts.  Visual Studio is compiling correctly on Windows 7...
To mention everything: I copied some c# en markup code and saved some GuestBook files with a different name to be able to base myself upon them and adapt everything to get it working... (as is done in the videos also)

When I go to the home page after a build and a setup on the site I get the error mentionned (way) below. 

I decided to also use also the comment control together with captcha in my module and thus am keeping these objects and code in my projects
The application hangs on the following line in Page_Load event in the LoadSettings() method because of a null reference of the edComment object: edComment.WebEditor.ToolBar = mojoPortal.Web.Editor.ToolBar.AnonymousUser;

When I remove all reference to these controls and code (that I don't really need for my tool's functionality), it gives a null reference error on the following line for the necessary btnSubmit object in the PopulateLabels() method: btnSubmit.Text b = ApplicationResources.SubmitButton;

It seems like it fails every time on an object I kept form the tutorial Guestbook files but don't know how to solve the issue.  The objects are defined in the designer file (designer.cs) of the ascx-control with their correct names.
I would like to prevent to have to restart the whole Module by adding this functionality manually.

Any tip or idea welcome!

Thanks
Pascal

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   LottoApplic.UI.LottoApplicModule.LoadSettings() +43
   LottoApplic.UI.LottoApplicModule.Page_Load(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Control.LoadRecursive() +146
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

8/17/2011 1:50:21 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

I think I had to post this in the Developper forum.  Could someone move my post if needed?  Thanks

8/17/2011 7:33:39 AM
Gravatar
Total Posts 18439

Re: NullReferenceExceptions objects creating new module

I've moved this post to the developer forum

make sure you are doing this in OnInit

SiteUtils.SetupEditor(this.edComment, true, Page);

so that the editor control is initialized before you start setting properties on it in LoadSettings

for this one:

btnSubmit.Text b = ApplicationResources.SubmitButton;

ApplicationResources should correspond to /App_GlobalResources/ApplicationResources.resx file in your custom project. Make sure your post build event is copying that file up to the App_GlobalResources folder under the mojoPortal.Web project (ie the Web/App_GlobalResources folder)

Hope that helps,

Joe

8/17/2011 9:34:25 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

Thanks for your reply Joe

It was set like this in the OnInit method:  SiteUtils.SetupEditor(edComment);  Changed into the overload you mentionned but still a null reference on those objects....
While debugiing I noticed that the SetupEditor method returned a null value for the edComment object...

 

8/18/2011 2:12:01 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

Noticed while debugging,  a null object is passed in the overloaded (prefered) method 'SetupEditor' for the EditorControl and the method returns since this is null:  if (editor == null) return;

Any tip on where to look or what to check /  do welcome.... Thanks

8/18/2011 6:37:05 AM
Gravatar
Total Posts 18439

Re: NullReferenceExceptions objects creating new module

do you have the editor control in your .ascx file?

my best guess is that in the .ascx file you have something incorrect for the "Inherits=" in the control declaration at the top so it is not loading the correct base class at runtime

8/19/2011 7:24:36 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

Thanks Joe
Control is present and am inheriting from the correct base class. Have been comparing with the Guestbook project as confirmation...

Wanted to set a breakpoint on the GuestBook code and check what is happening there but this wasn't working anymore either - Guestbook didn't appear anymore on the page when going to the site
This made me wonder if my solution hasn't become corrupted : I am using my solution on 2 different pc's and was sycnhronising the folder with a backup tool from and to an external hard disk and this maybe the cause somehow....

Therefore I've setup a new development solution and added the guestbook and my own projects, did some tests: Guestbook is working fine as expected, My custom module is installed and can be selected to put on a new page - BUT is not appearing on the page.
Don't have the error anymore though...

Am a bit stuck as beginner, but wil keep on trying and experimenting and will post if I find a solution to my problem as a learning curve for others

Any tip on how to trouble shoot or on how to get to know the framework better, always welcome...  Thanks

8/19/2011 7:35:01 AM
Gravatar
Total Posts 18439

Re: NullReferenceExceptions objects creating new module

are you sure your .ascx file is getting copied up to the web project using a post build event?

This error seems to indicate that the editor is not declared in the .ascx file, it must be there if it compiles ok in your project but it seems to not be there at runtime when it is using the copy beneath the mojoportal.web project so it makes me think it is not getting copied and is using an older version of the file that does not have the editor control in it.

If it is not appearing on the page it means an error happened and it can't load it, the error would be in the log under Administration > System Log

Hope that helps,

Joe

8/19/2011 9:11:59 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

You are right. It seems that my original error of null objects disappeared (or that code hasn't been hit yet) and that I'm having  problems on the button event handler now: 

In a habit I double clicked the button on the design page of the module control which generates a new event handler 'btnSubmit_Click1'. To be able to compile again I changed the method name to match the event handler name that worked before 'btnSubmit_Click'

Building the project worked fine, but the error was visible in the log of mojoportal site as you said. 

To solve the issue I removed all code and html related to the button and copied the one of Guestbook: not working, same error

Did a search on the wrong method name in the entire solution: 'btnSubmit_Click1': nothing found

Double clicked the button in GuestBook to see what happend with the handler:  Module didn't appear on the site page anymore aftwerwards --> this made me aware of my erroneous clicking of the button to create the eventhandler --> forgot that it is created /set in code

To solve this issue: I would need to know where this 'btnSubmit_Click1' is located?

I would maybe have given up already in other situations but mojoportal keeps me going :)

8/19/2011 11:09:13 AM
Gravatar
Total Posts 18439

Re: NullReferenceExceptions objects creating new module

when you double click a button in the designer it not only stubs out the event but also it puts an event declaration on the button like <asp:Button ... Click=

the VS designer assumes you have AutoEventWireup="true", but when you don't have that and you wire up the events yourself then you must remove the declaration from the button markup.

Hope that helps,

Joe

8/21/2011 5:38:53 AM
Gravatar
Total Posts 20
ScalSan

Re: NullReferenceExceptions objects creating new module

OK, thanks for reminding me of the basics of asp.net and markup...  Should have known that.

Still struggling though: isn't giving exception messages anymore on the SetupEditor but the edComment control is still null, instead the null exception comes on the line that adds the event handler on the button.  I think log4net suddenly catches the error (suddenly)

Moved up this method higher in the Oninit method: SiteUtils.SetupEditor(edComment); didn't help either !

Must still be missing or forgetting something...

Selecting the control with 'this.controlid' is working.  I suppose this means that all controls are present and correct names are used in code

Noticed that when I also use the 'this-object' of the page there's mentionned as base class while debugging: {ASP.name1app_name2withmoduleinit_ascx} where there's for the guestbook: {ASP.guestbook_guestbook_ascx} --> same control and featurename

Something tells me this is wrong and this is also the only difference I can find; In the codesmith definitions I must have most likely set these different names (to see the difference in functionality aftwerwards which is maybe blocking me now)

How can I fix this?  The  partial class name of my control already reflects the control name....

You must sign in to post in the forums. This thread is closed to new posts.