This one is driving me crazy. I have 4 text files that I have marked as Embedded Resources. I am trying to read one of the text files with this code
csharp
public static string GetMailTemplate(string name)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string contents = string.Empty;
try
{
Stream strm = assembly.GetManifestResourceStream(assembly.GetName().Name.ToString() + "." + name);
StreamReader reader = new StreamReader(strm);
while (reader.Peek() != -1)
{
contents += reader.ReadLine();
}
reader.Close();
return contents;
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
return string.Empty;
}
catch (ArgumentNullException ex)
{
Console.WriteLine(ex.Message);
return string.Empty;
}
}
When I run it I get an
ArgumentNullException on this line
csharp
Stream strm = assembly.GetManifestResourceStream(assembly.GetName().Name.ToString() + "." + name);
I am calling the above method like so
csharp
Console.WriteLine(TasksUtilities.GetMailTemplate("MailMessageTemplate14Days.txt"));
If you look at the screenshot below the files are definitely in the project

The only difference between this and other times Ive read embedded resources is this is a console application, but I wouldn't think that would make a difference?