Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code:

try
{

List<UsageProfile> result = new List<UsageProfile>();
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

if (defaultUsageProfilePath != "")
using (StreamReader reader = new StreamReader(assembly.GetManifestResourceStream(defaultUsageProfilePath)))
{
while (!reader.EndOfStream)
result.Add(new UsageProfile(reader.ReadLine()));
}
return result;
}
catch (Exception ex)
{
return null;

}

and it is stopping on

using (StreamReader reader = new StreamReader(assembly.GetManifestResourceStream(defaultUsageProfilePath)))

and it is saying:

Value cannot be null.\r\nParameter name: stream

how can i initialize stream?
Posted
Comments
Praveen Kullu 26-Jul-11 9:42am    
What is "defaultUsageProfilePath"? Have you passed some value to it? It must be null and that's why the problem.

The constructor of the StreamReader class throws the exception. It means assembly.GetManifestResourceStream(defaultUsageProfilePath) is returning null.
 
Share this answer
 
Did you remember to add the default assembly to the front of the file name you are trying to retrieve? Load your assembly into a disassembler (ILDasm is fine) to find out what the resource is actually called, and make sure your string matches.

The error is telling you the parameter to StreamReader is null, which is what happens when the resource loader can't find the resource you ask for. Forgetting that the namespace gets prepended by default is the usual reason that resource lookups fail.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900