I'm currently creating a game engine and needed to load images from resources in the client assembly which references my library. I'm using this code.
public static Image LoadImageFromResource(string name){
string asmname = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location).Replace('\\', '.').Replace('/', '.');
MessageBox.Show(asmname);
MessageBox.Show(asmname + "." + name.Replace('\\', '.').Replace('/', '.'));
/*164*/ return (Image)new Bitmap(Assembly.GetEntryAssembly().GetManifestResourceStream(asmname + "." + name.Replace('\\', '.').Replace('/', '.')));
}
And I'm calling this from the client test GECS_TEST.exe
/*11*/ Image img = Game.LoadImageFromResource("mario_left.png");
These are the outputs of the MessageBox
GECS_TEST
GECS_TEST.mario_left.png
And I'm getting this exception
System.ArgumentException: Value of 'null' is not valid for 'stream'.
at System.Drawing.Bitmap..ctor(Stream stream)
at GECS.Core.Game.LoadImageFromResource(String name) in C:\..\Game.cs:line 164
at GECS_TEST.Test.Main(String[] args) in c:\..\Test.cs:line 11
Thanks
Use Assembly.GetCallingAssembly() instead of Assembly.GetEntryAssembly().