Click here to Skip to main content
11,487,979 members (77,928 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF list stream
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 26-Jul-11 4:31am
adnama424
Comments
Praveen Kullu at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The constructor of the StreamReader class throws the exception. It means assembly.GetManifestResourceStream(defaultUsageProfilePath) is returning null.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 26 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100