I'm using VS 2010. I created a C# Class and compiled it to a DLL, then added a windows forms project to it to test the dll. I added a Reference to the DLL in the TestApp project in the Solution Explorer. Both projects compile without errors. But when I run the TestApp, I get a NullReferenceException when I call a method in the dll. The error says there is no instance of the object, which I unsterstand to be the method being called.
Everything I've done is the same as other DLL examples I've found on the internet. For example: http://msdn.microsoft.com/en-us/library/3707x96z(v=vs.100).aspx
http://coderock.net/how-to-create-a-dll-file-in-visual-studio-2010/
But I've obviously missed something basic.
// DLL Project
namespace SLink
{
public class AmpAPI
{
public String[] ReadID( Int32 id )
{
String[] result = new string[] { "A", "B", "C", "D" };
return result;
}
}
}
// Test Application
using SLink;
namespace TestApp
{
public partial class frmMain : Form
{
AmpAPI amp;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load( object sender, EventArgs e )
{
amp = new AmpAPI();
}
private void btnUpdate_Click( object sender, EventArgs e )
{
String[] result = new String[] { "", "", "", "" };
result = amp.ReadID( 0 ); // <-- NullReferenceException
}
}
}
