15

When i load a xxxx.XAML into WPF frame it throws the error ' ', hexadecimal value 0x0C, is an invalid character. Line 1, position 1. how to find which is causing the problem. when the xxxx.XAML is in another project's start page, it works fine, when i load that condent of xxxx.XAML in arother project means it throws an error why this is happening ?

And also i upgrade my project from vs 2010 to vs 2012

Karthi Keyan
  • 4,243
  • 5
  • 24
  • 47
BalaKrishnan웃
  • 4,337
  • 7
  • 30
  • 51
  • The problem is caused by a file that starts with a form feed. It shouldn't be hard to identify that. – user207421 Jan 16 '13 at 09:23
  • 3
    For me, what fixed this issue was setting the "Build Action" in the properties of the XAML file from "Page" to "Resource" – Jonathan Perry Nov 05 '13 at 09:41
  • 1
    What fixed it for me was the extra carriage returns and line feeds at the end of my .xaml file. They are invisible, hard to notice, but when I removed them, this error went away. – Ray Feb 28 '14 at 03:24

2 Answers2

13

In my case it was that I wanted to load a XAML file using the code below, but it's Build Action was set to Page instead of Resource:

Uri uri = new Uri(resourcePath, System.UriKind.Relative);
Stream stream = Application.GetResourceStream(uri).Stream;
UIElement view = (UIElement)XamlReader.Load(stream);
stream.Close();
XMight
  • 1,991
  • 2
  • 20
  • 36
  • 2
    Need not only to change Page to Resource, but also Custom Tool from MSBuild:Compile to nothing – Cel Oct 07 '16 at 09:25
  • Thanks, thanks a lot! I've been struggling with this simple task for a couple of hours now, I was starting o get infuriated, but I'm happy now :) – Hector Lazarin Nov 06 '22 at 02:57
3

In my file name, i have upper case X. while reading load the file i use small x. so it cause the problem

BalaKrishnan웃
  • 4,337
  • 7
  • 30
  • 51