object reference error when calling _presenter.OnViewInitialized();

Topics: Web Client Software Factory
May 5, 2008 at 10:47 PM
Hi there,

I'm using the code below in my application. All of my class libraries are included (well at least I think) but I get an object not set to the reference of an object error when I try to call the method below. It seems like the object builder is not working correctly.

What checks do I need to do in order to get this working?

Sean

private ProductsViewPresenter _presenter;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
_presenter.OnViewInitialized();
}
_presenter.OnViewLoaded();
}

CreateNew
public ProductsViewPresenter Presenter
{
get
{
return _presenter;
}
set
{
_presenter = value;
_presenter.View = this;
}
}

#region IProductsService Members


public IList<Products> Products
{
set { ProductsDataSource.DataSource = value; }
}


#endregion
Coordinator
May 5, 2008 at 11:28 PM
What is the full name of the base class for the Page?
If it is in System.Web, the OB won't work.
If it is Microsoft.Practices.CompositeWeb, the OB magic should happen.

Someone recently mentioned a problem with Server.Transfer messing up the pipeline, which may also be hurting you.

If the above does not help, let us know.
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
May 5, 2008 at 11:36 PM
Hi There Michael,

class declaration for the page . do I need to modify this line (System.Web.UI.Page)? I'm not sure I follow you correctly. Can you please give me more detail?

public partial class resultstest : System.Web.UI.Page, IProductsService
{




MichaelPuleio wrote:
What is the full name of the base class for the Page?
If it is in System.Web, the OB won't work.
If it is Microsoft.Practices.CompositeWeb, the OB magic should happen.

Someone recently mentioned a problem with Server.Transfer messing up the pipeline, which may also be hurting you.

If the above does not help, let us know.
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/

May 6, 2008 at 12:33 AM
Hi Michael,

I tried the following ( public partial class resultstest : Microsoft.Practices.CompositeWeb.Web.UI.Page, IProductsService ) and it compiled then I got another error:

Unable to cast object of type 'System.Web.HttpApplication' to type 'Microsoft.Practices.CompositeWeb.WebClientApplication'.

I created a global.asax file and then added the following namespaces and the base class. I still get the error. Can you help me fix the code please?

using System;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder;

then the class:

public class Global : WebClientApplication
{



MichaelPuleio wrote:
What is the full name of the base class for the Page?
If it is in System.Web, the OB won't work.
If it is Microsoft.Practices.CompositeWeb, the OB magic should happen.

Someone recently mentioned a problem with Server.Transfer messing up the pipeline, which may also be hurting you.

If the above does not help, let us know.
Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/

Coordinator
May 6, 2008 at 5:52 AM
This is very odd. Did you start with an existing application or did you start with a new Web Client application?
Also, what class does the actual global.asax (markup) class refer to? I hope it is your new derived class.
If you look at any of the quickstarts or sample apps, is there any obvious differences in the Global files?

Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
May 6, 2008 at 7:20 AM
Hi Michael,

I started with an existing application and then referenced the composite web in my project. I did try to add a global asax file to my project and then use the code below in that file but It keeps giving me that error. There must be something that i'm missing because the project compiles file it just wont run.

using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder;

/// <summary>
/// Summary description for Global
/// </summary>

public class Global : WebClientApplication
{
public Global()
{
}



}

quote:}
MichaelPuleio wrote:
This is very odd. Did you start with an existing application or did you start with a new Web Client application?
Also, what class does the actual global.asax (markup) class refer to? I hope it is your new derived class.
If you look at any of the quickstarts or sample apps, is there any obvious differences in the Global files?

Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/
{quote}
May 6, 2008 at 7:27 AM
Hi michael,

in my global asax I just placed this line of code at line 1 (<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>) and it's telling me that there is not build provider?

sean


MichaelPuleio wrote:
This is very odd. Did you start with an existing application or did you start with a new Web Client application?
Also, what class does the actual global.asax (markup) class refer to? I hope it is your new derived class.
If you look at any of the quickstarts or sample apps, is there any obvious differences in the Global files?

Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/

May 6, 2008 at 7:47 AM
Hi Michael,

I just deleted the global.asax and then copied the code below and voila it works. I published it to the drive and even closed the project and it's creating the object now. Thanks very much for your help.

sean


using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder;

namespace Wellcom.Toysrus.Public.Web
{

/// <summary>
/// Summary description for Global
/// </summary>

public class Global : WebClientApplication
{
public Global()
{
}



}
}



seankerr wrote:
Hi michael,

in my global asax I just placed this line of code at line 1 (<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>) and it's telling me that there is not build provider?

sean


MichaelPuleio wrote:
This is very odd. Did you start with an existing application or did you start with a new Web Client application?
Also, what class does the actual global.asax (markup) class refer to? I hope it is your new derived class.
If you look at any of the quickstarts or sample apps, is there any obvious differences in the Global files?

Michael Puleio - patterns & practices
Bloghttp://blogs.msdn.com/mpuleio/


May 6, 2008 at 1:51 PM

seankerr wrote:

Hi Michael,
I just deleted the global.asax and then copied the code below and voila it works. I published it to the drive and even closed the project and it's creating the object now. Thanks very much for your help.

using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder;
 
namespace Wellcom.Toysrus.Public.Web
{
 
    /// <summary>
    /// Summary description for Global
    /// </summary>
 
    public class Global : WebClientApplication
    {
        public Global()
        {
        }
    }
}


You will need the Global.asax file - there are events that are necessary, i.e., Application_Start. Your Global.asax should contain the following (using your above code). If you continue to get errors we'll have to get to the bottom of them.

<%@ Application Language="C#" Inherits="Wellcom.Toysrus.Public.Web.Global" %>