I have two projects in a solution (consider them as project1 and project2). The first project (project1) contains a class that holds global variables
public static class GlobalTrackInfo
{
public static string tracktitle { get; set; }
public static Uri trackUri { get; set; }
}
I added a reference of project1 in project2 and set values for the static variables as follows in a class of project2
GlobalTrackInfo.tracktitle = "myTitle";
GlobalTrackInfo.trackUri = new Uri("www.example.com");
Later I tried to access these variables in a class of project1 as
Title = GlobalTrackInfo.tracktitle;
But it appears to be null. What am I doing wrong? Is it not possible to use global variables across different projects ?
You can't share a static variable between two projects while they have their own AppDomain. According to MSDN documentation:
By default, each process using a DLL has its own instance of all the DLLs global and static variables..
If you want to do that it's better to use another approach such as network communication (IPC) or things like that.