XamlParseException - Image Pixels Manipulation with WPF C# / Kinect <p>I want to use this code to access the image pixels to be used with my Kinect code.. so i can replace the <strong>depth bits</strong> with the <strong>Image bits</strong>, so i created a WPF application and As soon as i run my code, i get this exception (it doesnt happen on a Console application) but i need this to run as a <strong>WPF application</strong> since . . i intend to use it with <strong>Kinect</strong></p> <p><strong>XamlParseException</strong></p> <blockquote> <p>'The invocation of the constructor on type 'pixelManipulation.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.</p> </blockquote> <p>Here is the code:</p> <pre><code>public partial class MainWindow : Window { System.Drawing.Bitmap b = new System.Drawing.Bitmap(@"autumn_scene.jpg"); public MainWindow() { InitializeComponent(); doSomethingWithBitmapFast(b); } public static void doSomethingWithBitmapFast(System.Drawing.Bitmap bmp) { Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = bmpData.Stride * bmp.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); byte red = 0; byte green = 0; byte blue = 0; for (int x = 0; x &lt; bmp.Width; x++) { for (int y = 0; y &lt; bmp.Height; y++) { //See the link above for an explanation //of this calculation (assumes 24bppRgb format) int position = (y * bmpData.Stride) + (x * 3); blue = rgbValues[position]; green = rgbValues[position + 1]; red = rgbValues[position + 2]; Console.WriteLine("Fast: " + red + " " + green + " " + blue); } } bmp.UnlockBits(bmpData); } } } </code></pre>