The requested object does not exist?

May 26, 2009 at 9:34 AM

I want to copy dircetory with vss

but i have some problems:

 VssHelper vss = new VssHelper(sVolume + @"\");                
 // Directory.Move(vss.DeviceName + sSourceDir, sTargetDir);

FileManagement oFM = new FileManagement();
oFM.RecursiveCopy(vss.DeviceName + sSourceDir, sTargetDir, sExt) ; //copy dir
vss.Delete();

sometimes dricetory copy do not compelet

and run

public void Delete()
        {           
            vss.DeleteSnapshot(this.output_SnapShotID, true);
        }
will through VssObjectNotFoundException

message: {"The requested object does not exist."}

please help me THX....

class fileManagement codes:

 private const long INVALID_HANDLE_VALUE = -1L;

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern long CopyFile([In] string lpExistingFileName, [In] string lpNewFileName, [In] ref byte bFailIfExists);
     
        public void  CopySpecificFile(string sSource, string sTarget)
        {
           
                byte bfileExit = 0;
                CopyFile(sSource, sTarget, ref bfileExit);
        }

        public ArrayList FindAllDirectories(string sPath)
        {
            FileInfo.WIN32_FIND_DATA wfd = new FileInfo.WIN32_FIND_DATA();
            ArrayList oList = new ArrayList();
            long hFile = (long)FindFirstFile(sPath, wfd);
            if (hFile != -1L)
            {
                do
                {
                    if ((((((wfd.dwFileAttributes & FileAttributes.Directory) > 0) && (string.Compare(wfd.cFileName, ".", true) != 0)) && (string.Compare(wfd.cFileName, "..", true) != 0)) ? 1 : 0) != 0)
                    {
                        oList.Add(wfd.cFileName);
                    }
                }
                while ((FindNextFile((IntPtr)hFile, wfd) == true));
            }
            FindClose((IntPtr)hFile);
            return oList;
        }

        public ArrayList FindAllFiles(string sPath)
        {
            FileInfo.WIN32_FIND_DATA wfd = new FileInfo.WIN32_FIND_DATA();
            ArrayList oList = new ArrayList();
            long hFile = (long)FindFirstFile(sPath, wfd);
            if (hFile != -1L)
            {
                do
                {
                    if ((wfd.dwFileAttributes & FileAttributes.Directory) == 0)
                    {
                        oList.Add(wfd.cFileName);
                    }
                }
                while ((FindNextFile((IntPtr)hFile, wfd) == true));
            }
            FindClose((IntPtr)hFile);
            return oList;
        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern bool FindClose([In] IntPtr hFind);
        [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
       private static extern IntPtr FindFirstFile([In] string lpszSearchFile, [In, Out] FileInfo.WIN32_FIND_DATA lpFindFileData);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
       private static extern bool FindNextFile([In] IntPtr hFind, [In, Out] FileInfo.WIN32_FIND_DATA lpFindFileData);

        public void RecursiveCopy(string sSourcePath, string sTargetPath, string sExt)
        {
           
            if (!sSourcePath.EndsWith(@"\"))
            {
                sSourcePath = sSourcePath + @"\";
            }
            if (!sTargetPath.EndsWith(@"\"))
            {
                sTargetPath = sTargetPath + @"\";
            }

            ArrayList oDirList = this.FindAllDirectories(sSourcePath + "*.*");

            //---Create each subdirectory in target path if it doesn't already exist.
            foreach (string sDirName in oDirList)
            {
                if (!Directory.Exists(sTargetPath + sDirName))
                {
                    Directory.CreateDirectory(sTargetPath + sDirName);
                }
            }

            ArrayList oFileList = this.FindAllFiles(sSourcePath + "*." + sExt);

            foreach (string sDirName in oDirList)
            {
                RecursiveCopy(sSourcePath + sDirName, sTargetPath + sDirName, sExt);
                  
            }   

            foreach (string sFile in oFileList)
            {
                CopySpecificFile(sSourcePath + sFile, sTargetPath + sFile);
                 
            }
           
        }

 

Sep 29, 2012 at 9:09 AM

A late answer, but in case it helps someone else...

about this error:

public void Delete()
        {            
            vss.DeleteSnapshot(this.output_SnapShotID, true);
        }
will through VssObjectNotFoundException

message: {"The requested object does not exist."}"

 

I had the same problem until I realized (reading MSDN) that before calling DeleteSnapshot(), you must call InitializeForBakup() AND SetContext(). Example;

 

IVssImplementation vssi = VssUtils.LoadImplementation();

 IVssBackupComponents  oVSS = vssi.CreateVssBackupComponents();            

oVSS.InitializeForBackup(null);

 oVSS.SetContext(VssSnapshotContext.All);

oVSS.DeleteSnapshot(my_snap_id, true);

oVSS.Dispose();