Out of the box "Could not load file or assembly Microsoft.Threading.Tasks.dll not found" error. #464

Closed
ahmetalpbalkan opened this Issue Feb 14, 2014 · 6 comments

5 participants

@ahmetalpbalkan
Microsoft Azure member

I am getting Microsoft.Threading.Tasks.dll not found error from management client I installed through NuGet. I cannot reproduce this on all machines but consistently happening on mine (VS2012/2013)

Stack trace

System.IO.FileNotFoundException was unhandled
  HResult=-2147024894
  Message=Could not load file or assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  Source=Microsoft.WindowsAzure.Management
  FileName=Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  FusionLog==== Pre-bind state information ===
LOG: DisplayName = Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///c:/users/ahmetb/documents/visual studio 2012/Projects/ConsoleApplication6/ConsoleApplication6/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.WindowsAzure.Management, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\ahmetb\documents\visual studio 2012\Projects\ConsoleApplication6\ConsoleApplication6\bin\Debug\ConsoleApplication6.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///c:/users/ahmetb/documents/visual studio 2012/Projects/ConsoleApplication6/ConsoleApplication6/bin/Debug/Microsoft.Threading.Tasks.DLL.
LOG: Attempting download of new URL file:///c:/users/ahmetb/documents/visual studio 2012/Projects/ConsoleApplication6/ConsoleApplication6/bin/Debug/Microsoft.Threading.Tasks/Microsoft.Threading.Tasks.DLL.
LOG: Attempting download of new URL file:///c:/users/ahmetb/documents/visual studio 2012/Projects/ConsoleApplication6/ConsoleApplication6/bin/Debug/Microsoft.Threading.Tasks.EXE.
LOG: Attempting download of new URL file:///c:/users/ahmetb/documents/visual studio 2012/Projects/ConsoleApplication6/ConsoleApplication6/bin/Debug/Microsoft.Threading.Tasks/Microsoft.Threading.Tasks.EXE.

  StackTrace:
       at Microsoft.WindowsAzure.Management.LocationOperations.ListAsync(CancellationToken cancellationToken)
       at Microsoft.WindowsAzure.Management.LocationOperationsExtensions.ListAsync(ILocationOperations operations)
       at ConsoleApplication6.Program.<Sample>d__0.MoveNext() in c:\Users\ahmetb\Documents\Visual Studio 2012\Projects\ConsoleApplication6\ConsoleApplication6\Program.cs:line 22
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__5(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
  InnerException: 

Repro steps

  1. Open Visual Studio 2012 or 2013, create new console application.
  2. Initialize client and paste the code below. (taken from readme)
  3. Install "Windows Azure Management Libraries" prerelease nuget package
  4. Run
  5. Exception thrown on ListAsync function

Code used:

namespace ConsoleApplication6
{
    using System;
    using System.Security.Cryptography.X509Certificates;
    using System.Threading.Tasks;
    using Microsoft.WindowsAzure;
    using Microsoft.WindowsAzure.Management;

    class Program
    {
        public static async void Foo()
        {
            string subscriptionId = @"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
            X509Certificate2 managementCertificate = new X509Certificate2(@"c:\rd\mgmt.cer");
            var credentials = new CertificateCloudCredentials(subscriptionId, managementCertificate);
            using (ManagementClient client = CloudContext.Clients.CreateManagementClient(credentials))
            {
                var result = await client.Locations.ListAsync();
                var locations = result.Locations;
                foreach (var location in locations)
                {
                    Console.WriteLine("Location: {0}", location.Name);

                    foreach (var feature in location.AvailableServices)
                    {
                        Console.WriteLine(feature);
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            Task.Factory.StartNew(Foo).Wait();
            Console.Read();
        }
    }
}

Screenshots

1
2
3

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.WindowsAzure.Common" version="0.9.8-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management" version="0.9.5-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Compute" version="0.9.9-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Libraries" version="0.9.6-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Monitoring" version="0.9.2-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Scheduler" version="0.9.8-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.ServiceBus" version="0.9.3-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Sql" version="0.9.4-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.Storage" version="0.9.3-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.VirtualNetworks" version="0.9.3-preview" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Management.WebSites" version="0.9.3-preview" targetFramework="net45" />
</packages>

csproj references section

<ItemGroup>
    <Reference Include="Microsoft.Data.Edm">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.Data.Edm.5.6.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Data.OData">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.Data.OData.5.6.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Data.Services.Client">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.Data.Services.Client.5.6.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Common">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Common.0.9.8-preview\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Common.0.9.8-preview\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Management, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Management.0.9.5-preview\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Management.Compute">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Management.Compute.0.9.9-preview\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Management.Storage">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Management.Storage.0.9.3-preview\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Management.VirtualNetworks">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Microsoft.WindowsAzure.Management.VirtualNetworks.0.9.3-preview\lib\net40\Microsoft.WindowsAzure.Management.VirtualNetworks.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.WindowsAzure.Storage">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\WindowsAzure.Storage.3.0.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Data.Services.Client" />
    <Reference Include="System.IO.Compression" />
    <Reference Include="System.IO.Compression.FileSystem" />
    <Reference Include="System.Net" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Net.Http.WebRequest" />
    <Reference Include="System.Spatial">
      <HintPath>$(SDXROOT)\services\fc\external\NuGet\System.Spatial.5.6.0\lib\net40\System.Spatial.dll</HintPath>
    </Reference>
    <Reference Include="System.XML" />
    <Reference Include="System.Xml.Linq" />
  </ItemGroup>

I can reproduce this very easily using steps above.

Edit: I just came across to a very recent SO question. If you need live repro, hit me up on Lync.

@ahmetalpbalkan
Microsoft Azure member

Installing "Microsoft Async" (Microsoft.Bcl.Async) nuget package mysteriously solves this error and client works as expected.

@ahmetalpbalkan
Microsoft Azure member

Status: repro acknowledged by @stankovski on

  • Microsoft Visual Studio Ultimate 2012 Version 11.0.61030.00 Update 4
  • NuGet Package Manager 2.8.50126.400
@stankovski
Microsoft Azure member

Thanks Ahmet for helping with the repro. The issue seems to be caused by the latest NuGet package. Working with NuGet team to get this fixed.

@rmenezes

Thanks @ahmetalpbalkan! Installing Microsoft Async dll saved my project. (Not in Azure, but in Xamarin the same problem occurred using Simple.OData.Client )

@markcowl
Microsoft Azure member

@ahmetalpbalkan This is fixed in the latest library.

@markcowl markcowl closed this Aug 7, 2014
@repoofkhadeer

I am getting below error,

Failed to add reference to 'Microsoft.Threading.Tasks.Extentions'. Please make sure that it is in the Global Assembly Cache.

Can some one help me to fix this ?

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment