question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

net40 application with Microsoft.Bcl.Async cannot resolve dependencies

See original GitHub issue

Steps to reproduce

Create a net40 application that references Microsoft.Bcl.Async and uses await: project.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net40</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" />
  </ItemGroup>

</Project>

Program.cs:

using System.Threading.Tasks;

class Program
{
    static void Main() => F().Wait();
    static async Task F() => await TaskEx.Delay(100);
}

Start with dotnet run

Expected behavior

Program should start.

Actual behavior

Creates errors

C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3268:
The primary reference "C:\Users\Schoenke\.nuget\packages\microsoft.bcl.async\1.0.168\lib\net40\Micro
soft.Threading.Tasks.dll" could not be resolved because it has an indirect dependency on the framewo
rk assembly "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50
a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0".
To resolve this problem, either remove the reference "C:\Users\Schoenke\.nuget\packages\microsoft.bc
l.async\1.0.168\lib\net40\Microsoft.Threading.Tasks.dll" or retarget your application to a framework
 version which contains "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b
03f5f7f11d50a3a". [C:\Users\Schoenke\Documents\Visual Studio 2017\Projects\NetCoreBCLTest\NetCoreBCL
Test\NetCoreBCLTest.csproj]
C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3268:
The primary reference "C:\Users\Schoenke\.nuget\packages\microsoft.bcl.async\1.0.168\lib\net40\Micro
soft.Threading.Tasks.Extensions.dll" could not be resolved because it has an indirect dependency on
the framework assembly "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b0
3f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Vers
ion=v4.0". To resolve this problem, either remove the reference "C:\Users\Schoenke\.nuget\packages\m
icrosoft.bcl.async\1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll" or retarget your appl
ication to a framework version which contains "System.Threading.Tasks, Version=1.5.11.0, Culture=neu
tral, PublicKeyToken=b03f5f7f11d50a3a". [C:\Users\Schoenke\Documents\Visual Studio 2017\Projects\Net
CoreBCLTest\NetCoreBCLTest\NetCoreBCLTest.csproj]
C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3268:
The primary reference "C:\Users\Schoenke\.nuget\packages\microsoft.bcl.async\1.0.168\lib\net40\Micro
soft.Threading.Tasks.dll" could not be resolved because it has an indirect dependency on the framewo
rk assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" whi
ch could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resol
ve this problem, either remove the reference "C:\Users\Schoenke\.nuget\packages\microsoft.bcl.async\
1.0.168\lib\net40\Microsoft.Threading.Tasks.dll" or retarget your application to a framework version
 which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
. [C:\Users\Schoenke\Documents\Visual Studio 2017\Projects\NetCoreBCLTest\NetCoreBCLTest\NetCoreBCLT
est.csproj]
C:\Program Files\dotnet\sdk\1.0.0\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3268:
The primary reference "C:\Users\Schoenke\.nuget\packages\microsoft.bcl.async\1.0.168\lib\net40\Micro
soft.Threading.Tasks.Extensions.dll" could not be resolved because it has an indirect dependency on
the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11
d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0
". To resolve this problem, either remove the reference "C:\Users\Schoenke\.nuget\packages\microsoft
.bcl.async\1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll" or retarget your application
to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyT
oken=b03f5f7f11d50a3a". [C:\Users\Schoenke\Documents\Visual Studio 2017\Projects\NetCoreBCLTest\NetC
oreBCLTest\NetCoreBCLTest.csproj]
Program.cs(9,40): error CS0103: The name 'TaskEx' does not exist in the current context [C:\Users\Sc
hoenke\Documents\Visual Studio 2017\Projects\NetCoreBCLTest\NetCoreBCLTest\NetCoreBCLTest.csproj]

The build failed. Please fix the build errors and run again.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0)

Product Information:
 Version:            1.0.0
 Commit SHA-1 hash:  e53429feb4

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x86
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0

Side Note: Similar behaviour with Microsoft.Net.Http which fails to resolve System.Net.Http.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:14
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
pizixiecommented, Apr 19, 2018

@rguryanov your example maybe work when OutputType is Exe,but Library did not

this problem had be solved in this by @ericstj

just to add

<AppConfig Condition="'$(TargetFramework)' == 'net40'">app.net40.config</AppConfig>
<AutoUnifyAssemblyReferences Condition="'$(TargetFramework)' == 'net40'">false</AutoUnifyAssemblyReferences>

app.net40.config like below:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
4reactions
rguryanovcommented, Apr 9, 2017

One workaround for that problem. Add import to Microsoft.Bcl.Build.targets in .csproj: <Import Project="..\Microsoft.Bcl.Build.targets" Condition="Exists('..\Microsoft.Bcl.Build.targets')" /> File Microsoft.Bcl.Build.targets can be found in packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets when you install Microsoft.Bcl.Async nuget in classic windows desktop app.

And add App.config to project (in vs add-> new item-> application configuration file):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
				<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
			</dependentAssembly>
			<dependentAssembly>
				<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
				<bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
			</dependentAssembly>
		</assemblyBinding>
	</runtime>
</configuration>

When you target multiple frameworks do remember to change condition for import and App.config. For example to something as

<Import Project="..\Microsoft.Bcl.Build.targets" Condition="Exists('..\Microsoft.Bcl.Build.targets') AND '$(TargetFramework)' == 'net40'" />
<ItemGroup Condition="'$(TargetFramework)' != 'net40'">
	<None Remove="app.config" />
</ItemGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

net40 application with Microsoft.Bcl.Async cannot resolve ...
Steps to reproduce Create a net40 application that references Microsoft.Bcl.Async and uses await: project.csproj: Exe net40.
Read more >
Microsoft.Bcl.Async package and modern csproj
Problem solved, Here the solution. Create a file called app.net40.config and put this content: <?xml version ="1.0"?> ...
Read more >
Microsoft.Bcl package dependency issue
Hi, I recently came to know that Microsoft.BCL NuGet package is deprecated. We have been using this package as a dependency with other...
Read more >
Microsoft.Bcl.AsyncInterfaces 7.0.0
Provides the IAsyncEnumerable and IAsyncDisposable interfaces and helper types for .NET Standard 2.0. This package is not required starting with .
Read more >
Build succeeding but missing dll
I tried asking this on StackOverflow but its hardly had any views in the past 24hrs. I'm finding my very simple web app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found