Click here to Skip to main content
16,009,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
namespace AppModule
{
public interface IMessageBox
{
void ShowMessageBox(String msg);
}

public partial class Form1 : Form
{

private readonly IMessageBox _messageBox;
public Form1(IMessageBox messageBox)
{

this._messageBox = messageBox;
}

public void Doit()
{
this._messageBox.ShowMessageBox("Test");
}
}
}

Error Message : An unhandled exception of type 'System.NullReferenceException' occurred in AppModule.exe

Additional information: Object reference not set to an instance of an object.

What I have tried:

I do know that messagebox is null but I don't understand how to initialize it. Pls help
Posted
Updated 19-Mar-20 22:08pm

1 solution

You need to create the implementation of your interface: interface - C# Reference | Microsoft Docs[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900