Click here to Skip to main content
15,877,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts

Wondering if anyone can help me here,I have written code like bellow in silverlight4 Application ,it basically just brings back some xml format for xaml and in my code .i am getting below error while run time..

illegal xml character [Line: 1 Position: 2]
this is the client code im using...

C#
public void LoadContent()
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();


    openFileDialog1.Filter = "XAML Files|*.xaml";
    bool? retval = openFileDialog1.ShowDialog();
    
    if (retval.HasValue && retval.Value)
    
        this.FilePath = openFileDialog1.File.Name;
        System.IO.Stream fileStream = openFileDialog1.File.OpenRead();

        object content = XamlReader.Load(fileStream.ToString());//falls over here             
        this.Content = content;
       
    }
}
Posted
Updated 24-Aug-12 22:23pm
v3
Comments
Richard MacCutchan 25-Aug-12 4:25am    
The message tells you what is wrong and where it is wrong; look at the XML that you are trying to read.

1 solution

The problem might be with the
C#
fileStream.ToString()


This will not load the XAML as a string, but "Sytem.IO.Filestream". I'm not used to Silverlight but the examples I have seen you should use

C#
object content = XamlReader.Load(fileStream.ReadToEnd());//


I hope this will work.
 
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