I am doing an application in c#.
I get the error:
Value cannot be null. Parameter name: stream while reading the contentxs of embedded file
in the code
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);
How to solve this error?
What I found is as once I faced this problem after adding a text file or template file to read the email body and than reading the path to that template file using below syntax:
Assembly asm = Assembly.GetExecutingAssembly();
string assemblyName = asm.GetName().Name;
string emailTemplateName = xyz.tt;
emailTemplateName = assemblyName + "." + emailTemplateName;
using (StreamReader reader = new StreamReader(asm.GetManifestResourceStream(emailTemplateName)))
{
body = reader.ReadToEnd();
}
The file by default gets added to project library with property "Build Action"= Content. I changed value from "Content" to "Embedded Resource" and everything worked good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With