Winform-CAB/Smart Client Software Factory: _presenter.OnViewReady NullReferenceException

No comments

When developing a module recently using Smart Client Software Factory

I got an exception I could not understand.

 

SCSF is using MVP- design and has some special attributes to create different objects, insert dependencies etc.

 

The problem was with a view and presenter using a well-used design , straight out from the wizard.

 

The following code is created by the Add view (with presenter) package/wizard (this is from the View):

 

 

 

       /// <summary>

        /// Sets the presenter. The dependency injection system will automatically

        /// create a new presenter for you.

        /// </summary>

        [CreateNew]

        public VisXMLPresenter Presenter

        {

            set

            {

                _presenter = value;

                _presenter.View = this;

            }

        }

 

        protected override void OnLoad(EventArgs e)

        {

            _presenter.OnViewReady();

        }

 

 

As the comments from the wizard so beautifully states: The dependency injection system will automatically

        /// create a new presenter for you

 

 

However, when running the module the OnLoad function was called before the _presenter was set,

leaving the _presenter at null, and generating the exception.

 

Which is very strange considering the framework/factory is handling the internal workings of generating the _presenter due to the [CreateNew] attribute. Add to that that this has been tested and used in many other modules by me and a lot others.

 

 

What was the problem? As usual, Google is my friend.

It seems that the Webbrowsercontrol I had dragged onto my form was the culprit.

This made the call to the OnLoad-function before the framework was finished doing it's magic.

 

The solution: add a Panel to the View/form first and add the Webbrowser to the panel.

This solves the issue until the Webbrowsercontrol itself starts behaving… :)

 

 

And here's the link I found using Googie: http://www.codeplex.com/smartclient/Thread/View.aspx?ThreadId=7559

 

 

 

Happy coding ;)

Posted via email from Henris blogg

No comments :

Post a Comment