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>”);

        }

    }

}

 

 

Comments (7)

  1. Takekazu Omi says:

    In VS 2010 console Application, default is 4.0 client profile.  The time you can not use Azure library.

    If you use 4.0 full profile. It works fine. Just try it.

  2. Ashwini says:

    Hi,

    Thanks . It resolved my error.

    Ashwini

  3. Antonio says:

    Thank you. This simple fix has made my day

  4. daniel says:

    thanks it helps 🙂

  5. Filiz says:

    Thanks. You saved me at least  a couple of hours:)

  6. jack says:

    thank you!!!!It works!!

  7. Dinesh Prasanth says:

    Thank you so much.. solved the problem… 🙂