Console application using Windows Azure Storage Client Library with Windows Azure SDK

If you create a Console Application in VS 2010:

1. Add reference
DLL:

Microsoft.WindowsAzure.StorageClient

1. Add code:

using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.StorageClient;

When you compile this application you will get the following
error:

Error Details:

  • The referenced assembly "Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
  • The type or namespace name 'WindowsAzure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

If you check application settings for .NET platform version, you will see .NET platform version is set to 4.0 Client Profile by default thats why you received this error. Now if you can change the .NET platform version to 3.5 or 4.0 and recompile the
application and error will be resolved.  

Here is the sample code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.WindowsAzure.StorageClient;

using Microsoft.WindowsAzure;

 

namespace AzureStroageTest

{

    class Program

    {

        private static CloudStorageAccount account;

        private static CloudBlobClient blobClient;

        private static CloudBlobContainer container;

 

        public static void ConnectStorage(string containerName)

        {

                account = new CloudStorageAccount(new StorageCredentialsAccountAndKey("<Enter_storage_account_name>", "<Enter_storage_account_key>"), true);

                blobClient = new CloudBlobClient(account.BlobEndpoint.AbsoluteUri, account.Credentials);

                container = blobClient.GetContainerReference(containerName);

                container.CreateIfNotExist();

                Console.WriteLine("Success");

        }

 

        static void Main(string[] args)

        {

            ConnectStorage("<Enter_container_name>");

        }

    }

}