Click here to Skip to main content
11,703,617 members (63,503 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WPF list stream
I am using this code:


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 3:31am
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
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.
Rate this: bad
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.

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

  Print Answers RSS
0 OriginalGriff 550
1 Maciej Los 530
2 Sergey Alexandrovich Kryukov 381
3 Andy Lanng 294
4 CPallini 195
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web02 | 2.8.150819.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