Tuesday, October 14, 2008 9:07 PMHey all,
I am getting the following error when calling the PrintHelp function below:
System.ArgumentNullException was unhandled
Message="Value cannot be null.\r\nParameter name: stream"
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(Stream stream)
at ConvertCounterData.Program.PrintHelp() in C:\Documents and Settings\...\ConvertCounterData\Program.cs:line 323
at ConvertCounterData.Program.Main(String args) in C:\Documents and Settings\...\ConvertCounterData\Program.cs:line 20
at System.AppDomain.nExecuteAssembly(Assembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
public static void PrintHelp()I checked the Resources tab and my text file is there.
What am I missing here?
Tuesday, October 14, 2008 10:48 PMSince you say that you added the file as a resource (under the Project, ProjectName Properties, Resource tab), there is a very easy way to get its contents.
(Assumes that you chose FileType of Text in the Properties box for that resource. Otherwise, you would get a byte.)
Note that resources that you add through that tab are not directly accessible as "manifest resources". (Behind the scenes, .NET bundles all of the resources that you add using that tab into a single manifest resource for your assembly.)
To add and use a "manifest" resource directly, you do not need to use the Resources tab.
1. Make sure that the file is part of your project in Solution Explorer (for example, via Add, Existing Item).
2. Select the file in Solution Explorer and set the Build Action to "Embedded Resource".
3. Obtain and access Stream as follows (note that the resource name is prefixed with the name of the assembly):
- Marked As Answer by Maximusdm Wednesday, October 15, 2008 12:10 AM
Wednesday, October 15, 2008 12:11 AMIt worked using the second method