0

I am debugging an asp.net application. It works flawlessly in test environment, however, I am getting null reference exception in real server. I am using ninject. The problem arose from ninject I suppose.Here is the problematic code fragment:

public partial class PersonelAylikRapor : MasterClass
{
    protected void btnSorgula_Click(object sender, EventArgs e)
    {
        //other codes ommited for brevity
        DateTime baslangicTarihi = DateTime.MinValue;

        //arac is null here. 
        baslangicTarihi = this.arac.CevirDateTimea("01." + ddlAy.SelectedValue + "." + ddlYil.SelectedValue);       

    }
}

the variable arac should have been solved in MasterClass, since it is the father class, so I do not check null reference issue.

MasterClass is the place that I set the ninject kernel. Here is the content of the MasterClass:

public class MasterClass : System.Web.UI.Page
{

IKernel ninjectKernel = null;
private bool cekirdekKurulduMu = false;
public IPersonelIsKurali personelik = null;    
public IAraclarTaha arac = null;
public ITurnikePersonelIsKurali turnikepersonelik = null;
public IPersonelBirimlerIsKurali personelbirimlerik = null;
public ITurnikeIslemlerIsKurali turnikeIsKurali = null;
public IPersonelIliskilendir personelilisiklendirik = null;
public IBirimlerIsKurali birimlerik = null;
public IPersonelIzinIsKurali personelizinik = null;
public IServisIsKurali servisIsKurali = null;
public FonksiyonSonuc fs = null;
public List<PersonelKunye> listpersonelkunye = null;
public List<uint> listgorebilecegipersonelid = null;

public MasterClass()
{

}

protected override void OnPreInit(EventArgs e)
{   
    try
    {
        base.OnPreInit(e);

        if (this.cekirdekKurulduMu == false)
        {

            this.cekirdekKurulduMu = true;
            this.ninjectKernel = new StandardKernel();
            this.ninjectCekirdegiKur(this.ninjectKernel);
            this.DegiskenlereAta();
        }

    }
    catch (Exception ex)
    {
        IAraclarTaha arac = new AraclarTaha();
        FonksiyonSonuc fs = new FonksiyonSonuc(true);

        fs = arac.HatayiVeritabaninaYaz(ex, OrmanSuTypes.Enums.HataCiddiyetiEnum.OLUMCUL);

        if (fs.fonksiyonBasariDurumu == false)
        {

            throw ex;
        }


    }
}

private void ninjectCekirdegiKur(IKernel ninjectKernel)
{


    this.ninjectKernel = new StandardKernel();
    this.ninjectKernel.Bind<IPersonelBirimlerIsKurali>().To<PersonelBirimlerIsKurali>();
    this.ninjectKernel.Bind<IPersonelIzinIsKurali>().To<PersonelIzinIsKurali>();
    this.ninjectKernel.Bind<IPersonelIsKurali>().To<PersonelIsKurali>();
    this.ninjectKernel.Bind<IAraclarTaha>().To<AraclarTaha>().WithConstructorArgument("debugMode", Araclar.DebugModdaMi());
    this.ninjectKernel.Bind<ITurnikeIslemlerIsKurali>().To<TurnikeIslemlerIsKurali>();
    this.ninjectKernel.Bind<IBirimlerIsKurali>().To<BirimlerIsKurali>();
    this.ninjectKernel.Bind<IPersonelIliskilendir>().To<PersonelIiskilendirIsKurali>();
    this.ninjectKernel.Bind<ITurnikePersonelIsKurali>().To<TurnikePersonelIsKurali>();
    this.ninjectKernel.Bind<IServisIsKurali>().To<ServisIsKurali>();


}

    public void DegiskenlereAta()
{


    if (this.arac == null)
    {
        this.arac = this.ninjectKernel.Get<IAraclarTaha>();
    }
    if (this.personelik == null)
    {
        this.personelik = this.ninjectKernel.Get<IPersonelIsKurali>();
    }
    if (this.turnikepersonelik == null)
    {
        this.turnikepersonelik = this.ninjectKernel.Get<ITurnikePersonelIsKurali>();
    }
    if (this.personelbirimlerik == null)
    {
        this.personelbirimlerik = this.ninjectKernel.Get<IPersonelBirimlerIsKurali>();        
    }
    if (this.turnikeIsKurali == null)
    {
        this.turnikeIsKurali = this.ninjectKernel.Get<ITurnikeIslemlerIsKurali>();
    }
    if (this.personelilisiklendirik == null)
    {
        this.personelilisiklendirik = this.ninjectKernel.Get<IPersonelIliskilendir>();
    }
    if (this.birimlerik == null)
    {
        this.birimlerik = this.ninjectKernel.Get<IBirimlerIsKurali>();
    }
    if (this.personelizinik == null)
    {
        this.personelizinik = this.ninjectKernel.Get<IPersonelIzinIsKurali>();
    }
    if (this.fs == null)
    {
        this.fs = new FonksiyonSonuc(true);
    }
    if (this.servisIsKurali == null)
    {
        this.servisIsKurali = this.ninjectKernel.Get<IServisIsKurali>();
    }

}

}

What is wrong with it? Thanks in advance.

Edit-1: Here is the visual explanatory of the error: Application Error

Jongware
  • 22,200
  • 8
  • 54
  • 100
tahasozgen
  • 469
  • 5
  • 27
  • 2
    If it *works flawlessly in test environment* as you describe, I would bet the problem isn't with your code and there is some configuration difference between your test and prod webservers. I would start there and figure out what's different? (Perhaps test has a .dll prod doesn't...etc) – mituw16 Aug 19 '16 at 11:17
  • What is the actual exception that you are getting? – ArunGeorge Aug 19 '16 at 11:20
  • You are getting a null reference... not null pointer.. – Gilad Green Aug 19 '16 at 11:27
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Gilad Green Aug 19 '16 at 11:28
  • dear mituw16; What should I do for that? I double check the dlls and test dlls and production dlls are same. – tahasozgen Aug 19 '16 at 11:28

1 Answers1

0

I have just solve that problem. You can not set your ninject kernel in such manner. Implementing ninject kernel in asp.net web forms are expressed here:

How can I implement Ninject or DI on asp.net Web Forms?

Community
  • 1
  • 1
tahasozgen
  • 469
  • 5
  • 27