Thank you for visiting the Rackspace Community
The The Community is live! Post new content or topics so our teams can assist.

Please contact your support team if you have a question or need assistance for any Rackspace products, services, or articles.

.net CopyObject not found error

This question has suggested answer(s).

I am copying objects from one container to another in preparation for a renaming of objects in bulk.  The code works but errors out when an object is not found.  When checking the source container the object returns a 404 and just needs to be purged.

Is there any way to handle that exception without using the GetObject method before copying?  I see where GetObject will return an exception but this will add a lot of overhead to the I/O

All Replies
  • Can you post some of the code? I'm not sure I completely understand your issue, and seeing the code will help. Thanks.

    -- Don Schenck

  • private static void CopyObjects(IObjectStorageProvider provider, string containerName)
    {

    Console.WriteLine("Objects in container {0}", containerName);

    var backupName = string.Format("{0}_backup", containerName);

    foreach (ContainerObject containerObject in ListAllObjects(provider, containerName))
    {
    Console.WriteLine("Copying {0}", containerObject.Name);
    provider.CopyObject(containerName, containerObject.Name, backupName, containerObject.Name);
    }

    }

    The unhadled exception occurs if the containerObject does not exist but still has not been purged.  The only option I know of is performing a GetObject prior to the CopyObject and handle the error.

  • While not elegant, can you put a Try-Catch around the `CopyObject` line and Catch any exception and continue processing?

  • try that but still get this error:

    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: net.openstack.Core.Exceptions.Response.ItemNotFoundException
    Stack:
    at net.openstack.Providers.Rackspace.Validators.HttpResponseCodeValidator.Validate(JSIStudios.SimpleRESTServices.Client.Response)
    at net.openstack.Providers.Rackspace.ProviderBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CheckResponse(JSIStudios.SimpleRESTServices.Client.Response)
    at net.openstack.Providers.Rackspace.ProviderBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].ExecuteRESTRequest[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](net.openstack.Core.Domain.CloudIdentity, System.Uri, JSIStudios.SimpleRESTServices.Client.HttpMethod, System.Object, System.Collections.Generic.Dictionary`2<System.String,System.String>, System.Collections.Generic.Dictionary`2<System.String,System.String>, Boolean, Boolean, JSIStudios.SimpleRESTServices.Client.RequestSettings, System.Func`7<System.Uri,JSIStudios.SimpleRESTServices.Client.HttpMethod,System.String,System.Collections.Generic.Dictionary`2<System.String,System.String>,System.Collections.Generic.Dictionary`2<System.String,System.String>,JSIStudios.SimpleRESTServices.Client.RequestSettings,System.__Canon>)
    at net.openstack.Providers.Rackspace.ProviderBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].ExecuteRESTRequest(net.openstack.Core.Domain.CloudIdentity, System.Uri, JSIStudios.SimpleRESTServices.Client.HttpMethod, System.Object, System.Collections.Generic.Dictionary`2<System.String,System.String>, System.Collections.Generic.Dictionary`2<System.String,System.String>, Boolean, Boolean, JSIStudios.SimpleRESTServices.Client.RequestSettings)
    at net.openstack.Providers.Rackspace.CloudFilesProvider.CopyObject(System.String, System.String, System.String, System.String, System.String, System.Collections.Generic.Dictionary`2<System.String,System.String>, System.String, Boolean, net.openstack.Core.Domain.CloudIdentity)
    at RackSpaceLoadCDN.Program.CopyObjects(net.openstack.Core.Providers.IObjectStorageProvider, System.String)
    at RackSpaceLoadCDN.Program.Main(System.String[])

  • Give the following a try and if you continue to receive that exception, please post back with your code snippet.

    
    private static void CopyObjects(IObjectStorageProvider provider, string containerName)
    {
        Console.WriteLine("Objects in container {0}", containerName);
    
        var backupName = string.Format("{0}_backup", containerName);
    
        foreach (ContainerObject containerObject in ListAllObjects(provider, containerName))
        {
            Console.WriteLine("Copying {0}", containerObject.Name);
            try
            {
                provider.CopyObject(containerName, containerObject.Name, backupName, containerObject.Name);
            }
            catch (net.openstack.Core.Exceptions.Response.ItemNotFoundException)
            {
                // TODO: Handle the item no longer existing in the source container.
                Console.WriteLine("Cannot copy {0} as it no longer exists", containerObject.Name);
            }
        }
    }