Data at the root level is invalid. Line 1, position 1.' XML is not valid and Markup file is not valid. Specify a source markup file with an .xaml extension

hello all

I wrote a code in C#console application visual studio 2010 to split desktop but that is giving two error messages.

I took code from given below link. that code first gave an error that fixed by help of this network later that code gave another error that was also fixed but now for these two errors I couldn't find appropriate posts on internet so asked question.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

public class VirtualDesktop : IDisposable
{
    // These security descriptors below are required to let us manipulate the desktop objects.
    internal enum DESKTOP_ACCESS_MASK : uint
    {
        DESKTOP_NONE = 0,
        DESKTOP_READOBJECTS = 0x0001,
        DESKTOP_CREATEWINDOW = 0x0002,
        DESKTOP_CREATEMENU = 0x0004,
        DESKTOP_HOOKCONTROL = 0x0008,
        DESKTOP_JOURNALRECORD = 0x0010,
        DESKTOP_JOURNALPLAYBACK = 0x0020,
        DESKTOP_ENUMERATE = 0x0040,
        DESKTOP_WRITEOBJECTS = 0x0080,
        DESKTOP_SWITCHDESKTOP = 0x0100,

        EVERYTHING = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
                      DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
                      DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
    }

    #region Variables
    public IntPtr DesktopPtr;     // This will point to the current desktop we are using.
    private string _sMyDesk;      // This will hold the name for the desktop object we created.
    IntPtr _hOrigDesktop;         // This will remember the very first desktop we spawned on.
    #endregion

    #region DLL Definitions
    [DllImport("user32.dll", EntryPoint = "CloseDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool CloseDesktop(IntPtr handle);

    [DllImport("user32.dll")]
    private static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode,
                                               int dwFlags, long dwDesiredAccess, IntPtr lpsa);

    [DllImport("kernel32.dll")]
    public static extern int GetCurrentThreadId();

    [DllImport("user32.dll")]
    public static extern IntPtr GetThreadDesktop(int dwThreadId);

    [DllImport("user32.dll")]
    public static extern bool SetThreadDesktop(IntPtr hDesktop);

    [DllImport("user32.dll")]
    private static extern bool SwitchDesktop(IntPtr hDesktop);
    #endregion

    #region Disposal Methods
    // Switch to the desktop we were on before.
    public void Dispose()
    {
        SwitchToOrginal();
        ((IDisposable)this).Dispose();
    }

    // Delete our custom one.
    protected virtual void Dispose(bool disposing)
    {
        if (disposing)
        {
            CloseDesktop(DesktopPtr);
        }
    }

    // ... flush!
    void IDisposable.Dispose()
    {
        Dispose(true);

        // This takes the already destroyed desktop off the finalization queue so the GC
        // doesnt call the finalization code twice.
        GC.SuppressFinalize(this);
    }
    #endregion

    #region Methods
    public IntPtr GetCurrentDesktopPtr()
    {
        return GetThreadDesktop(GetCurrentThreadId());
    }

    private IntPtr LaunchDesktop()
    {
        return CreateDesktop(_sMyDesk, IntPtr.Zero, IntPtr.Zero,
                             0, (long)DESKTOP_ACCESS_MASK.EVERYTHING, IntPtr.Zero);
    }

    public void ShowDesktop()
    {
        SetThreadDesktop(DesktopPtr);
        SwitchDesktop(DesktopPtr);
    }

    public void SwitchToOrginal()
    {
        SwitchDesktop(_hOrigDesktop);
        SetThreadDesktop(_hOrigDesktop);
    }
    #endregion

    #region Constructors
    public VirtualDesktop()
    {
        _sMyDesk = "";
    }

    public VirtualDesktop(string sDesktopName)
    {
        _hOrigDesktop = GetCurrentDesktopPtr();
        _sMyDesk = sDesktopName;
        DesktopPtr = LaunchDesktop();
    }
    #endregion
}


please have a look at errors 

Error 1 Markup file is not valid. Specify a source markup file with an .xaml extension. C:\Users\a\documents\visual studio 2010\Projects\VirtualDesktop\VirtualDesktop\Program.cs VirtualDesktop

Error 2 'Data at the root level is invalid. Line 1, position 1.' XML is not valid. C:\Users\a\documents\visual studio 2010\Projects\VirtualDesktop\VirtualDesktop\Program.cs 1 1 VirtualDesktop

February 25th, 2015 10:52pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics