Click here to Skip to main content
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 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 26 Jul 2011
Copyright © CodeProject, 1999-2014
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