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.
Looks like it's not finding your resource.
Try: "DatabaseConnectionTests.Resources.index.jpg"
Set a breakpoint in a class in the same assembly and evaluate this:
this.GetType().Assembly.GetManifestResourceNames()
That will list all resource names avail for that assembly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.