ASP.net app crashes - Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop'

前端 未结 4 1758
离开以前
离开以前 2020-12-09 04:24

I want to build a Google BigQuery C# ASP.net application using OAuth2 and the .Net 4.5 framework. I ran these NuGet installs

Install-Package Google.Apis.Bigq         


        
相关标签:
4条回答
  • 2020-12-09 04:29

    I already encountered this error before. It looks like the Bcl.Async package contains a reference to Microsoft.Threading.Tasks.Extensions.Desktop when you run a .NET 4.0 applications but somehow it is missing in .NET 4.5 application.

    My advice for you (until I'll figure our with the owner of Microsoft.Bcl.Async why it happens) is to copy Microsoft.Threading.Tasks.Extensions.Desktop from packages\Microsoft.Bcl.Async.1.0.165\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll to your BIN folder. It should solve this issue.

    UPDATE (March 17th): Consider adding the following Post-build event to your project:

    copy /Y "$(SolutionDir)packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll" "$(TargetDir)Microsoft.Threading.Tasks.Extensions.Desktop.dll"

    Unfortunately, there isn't a solution for this problem yet from the owners of the Bcl.Async package.

    0 讨论(0)
  • 2020-12-09 04:32

    This approach did not fix the issue - I got the same runtime error. But after a rebuild, I noticed that the VS2013 compiler showed this warning, which I formatted a little for the SO editor

    C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning
    MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual 
    Studio, double-click this warning (or select it and press Enter) to fix the conflicts; 
    otherwise, add the following binding redirects to the "runtime" node in the application 
    configuration file:
    
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
            <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0" />
        </dependentAssembly>
    </assemblyBinding>
    

    so I dropped the suggested block in the app web.config file. Then the app decided to work. I have no idea why it works now, but I get the impression that the XML block and / or the reference fix you mentioned somehow touched the Microsoft.Threading.Tasks.Extensions.Desktop DLL, or some low-level machinery inside .Net, or both. Or neither, for all I know. Anyway, thanks for your help. I only wish I had a better understanding of the internal machinery.

    0 讨论(0)
  • 2020-12-09 04:46

    They released a new version of -Package Microsoft.Bcl.Async.

    If somebody has this issue, please install the "latest" version instead of 1.0.16.

    I hope it works for you.

    0 讨论(0)
  • 2020-12-09 04:50

    Because the error is based on the fact that the latest version of Microsoft.Bcl.Async doesn't work in .NET 4.5, you can try to do the following:

    Open your Package Manager Console, and run the following commands:
    1) Uninstall-Package Microsoft.Bcl.Async -Force
    2) Install-Package Microsoft.Bcl.Async -Version 1.0.16

    It works in a sample I'm currently writing. Please let me know if it works for you.

    UPDATE (March 21st): You can update the package (new version 1.0.166-beta is available - https://www.nuget.org/packages/Microsoft.Bcl.Async/1.0.166-beta).
    I tested it on VS2013 with .NET 4.5 framework and it works.

    0 讨论(0)
提交回复
热议问题