I'm trying to get an image in the resources as a byte[]
for insertion into a database. The resource is at Resources/CatSeal and is a file called index.jpg.
I've looked at this question, but I'm still having trouble. I'm getting a NullReferenceException on the indicated line. My namespace is DatabaseConnectionTests
. According to this documentation, under "Access Resources" it should follow this format, which I believe I'm doing:
MyNameSpace.MyImage.bmp
Here's my code:
Stream sourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DatabaseConnectionTests.index.jpg");
using (var memoryStream = new MemoryStream())
{
sourceStream.CopyTo(memoryStream); // NullReferenceException here
seal.SealerImage = memoryStream.ToArray();
}
sealDatabaseOperations.Insert(seal);
How can I resolve this so that my resource image is loaded to a byte[]
? Thanks in advance.