ASP.NET Core referencing TPL NuGet package Cannot Find File or Assembly System.Threading - .net-4.0

I am making a new ASP.NET Core 2.0 project, essentially a Web API. I have to reference several assemblies that are .NET 3.5 assemblies, so I am running this as a .NET Framework project, just using the .NET Core improvements where possible.
The referenced .NET framework 3.5 assembly references TaskParallelLibrary (1.0.2856). And I think that's where my issues are coming in. It's worth noting the Web API worked on its sample endpoints and all worked as expected.
When I run the application and try and use the referenced library, the call fails and I receive the following exception:
Could not load file or assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
or one of its dependencies. The system cannot find the file specified.
I have tried several things, including:
Adding an App.configx file to try and force it to target .NET framework 4's System.Threading, on the assumption that that will be available. Inspired by a page I can't find the link for:
Here's the content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- this is only here for binding redirects -->
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Directly adding the TaskTPLLibrary package at that version to the project. So far, it hasn't helped.
Adding the Microsoft.Bcl.Async library to my project. Again, nothing.
Trying to directly import System.Threading from "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Threading.dll". I get an error stating "The reference is invalid or unsupported."
I've tried several other things, including re-cloning, cleaning, re-cleaning, swearing vociferously and coming back at it another day, all to no avail.
My reading list includes (on this computer):
https://github.com/dotnet/corefx/issues/26084
Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0
ASP.NET Core 2.0 Site - FileIOException System.Runtime
And probably others that I can't remember
Some additional information as this issue continues:
Creating a .NET Framework ASP.NET MVC app using .NET Framework 4.6.2 with the same underlying library does work. It does it indirectly using an intermediary .NET Framework 3.5 one (just for convenience as much as anything else).
A .NET Framework 4.6.2 Console App that uses the library directly also runs into this problem. So it seems not to be ASP.NET Core itself. I'll change the tags accordingly.
Making the 4.6.2 console use the intermediary 3.5 library doesn't resolve the issue.
Any help in resolving this issue much appreciated.

As there's no reasonable answer forthcoming, I'm assuming that having a .NET 3.5 Framework library referenced that uses the TaskParallelLibrary will in essence mean that using any .NET above 4 will cause this error. Under unspecified conditions. Most of the time.
The only solution to this seems to be rewrite everything to multi-target .NET 3.5 and .NET Standard and have the Standard implementation use the real TPL and have the 3.5 one use the NuGet package.

Related

Which packages to reference in Microsoft.NET.Sdk.Razor project to get full ASP.NET Core

I want to create a modular Web application using ASP.NET Core.
So my structure is to have a full ASP.NET Core application project
<Project Sdk="Microsoft.NET.Sdk.Web">
and multiple projects of type
<Project Sdk="Microsoft.NET.Sdk.Razor">
The reason for using Microsoft.NET.Sdk.Razor is that it doesn't require a Program.cs with a static Main method.
However, when I try to reference e.g. IViewLocationExpander it is not available due to the lack of some assembly references.
My problem now is which version of the overwhelming list of Microsoft.AspNetCore.* packages to pick in which version (for .NET 6 I expect to be something like 6.0.12).
IViewLocationExpander is part of Microsoft.AspNetCore.Mvc.Razor in assembly Microsoft.AspNetCore.Mvc.Razor (Microsoft.AspNetCore.Mvc.Razor.dll`).
But Microsoft.AspNetCore.Mvc.Razor is only available until version 2.2.0 so it seems to be outdated.
How do I solve this?
Using <FrameworkReference Include="Microsoft.AspNetCore.App" /> in your project file should do the trick - it avoids a lot of the headaches with working out which packages to reference and gets you all the Razor ones (and all the other useful ASP.NET Core bits) out of the box.
As mentioned by #Alexander in the comments the docs for this are here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-6.0

ASP.NET Core 2.0 Could not load file or assembly System.ServiceModel

I am working on porting an "ASP.NET Core Web Application" that was compiling under the .NET Framework 4.6.1 (i.e. full framework) over to compiling against .NET Core 2.0. I have some dependencies which still require the full framework but with .NET 2.0 my understanding is that I can now reference full framework assemblies from within a .NET Core 2.0 compiled application.
When I attempt to run the project, I get the following error:
Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
I looked through all the NuGet packages and projects I'm referencing and none of them reference System.ServiceModel.Web but I'm not convinced that's the same as the System.ServiceModel. When I open the projectname.deps.json file located in the bin folder, I see a reference to System.ServiceModel.Web but no reference to System.ServiceModel under the "Microsoft.NETCore.App/2.0.0" section which contains the following line:
"ref/netcoreapp2.0/System.ServiceModel.Web.dll": {},
I also poked around in the "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0" folder and I see a System.ServiceModel.Web.dll.
I'm not doing any WCF work and as I stated I've looked at all the dependencies of the libraries I'm using and none of them appear to be referencing System.ServiceModel.
Has anyone else run into this issue? I appreciate any and all insights anyone might have.
I solved this problem installing the Nuget package:
Install-Package Microsoft.Windows.Compatibility
I was using ASP.net Core 2.2 but maybe works for 2.0v too
In Asp.Net Core, when the Microsoft WCF Web Service Reference Provider is used under the connected services, code generator automatically includes System.ServiceModel.Duplex, System.ServiceModel.Http, System.ServiceModel.NetTcp, System.ServiceModel.Security'assemblies.
<PackageReference Include="System.ServiceModel.Duplex" Version="4.4.*" />
<PackageReference Include="System.ServiceModel.Http" Version="4.4.*" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.*" />
<PackageReference Include="System.ServiceModel.Security" Version="4.4.*" />
In your occasion, System.ServiceModel.Primitives is needed to be added aswell. System.ServiceModel.Primitives assembly includes System.ServiceModel.dll
System.ServiceModel, Version=4.0.0.0 is not used anymore.
please also see: https://github.com/dotnet/standard/issues/575#issuecomment-380479584

System.IO.FileNotFoundException with Pivotal.Gemfire.dll

I am installing a C# windows service that uses Geode onto a UAT Windows 2012 server. The referenced dll (like log4net, newtonsoft.json and QuickFix) are working except for Pivotal.Gemfire.dll
When I start the service I get System.IO.FileNotFoundException: Could not load file or assembly 'Pivotal.Gemfire.dll' or one of its dependencies. The specified module could not be found. File name: 'Pivotal.Gemfire.dll'
Now Gacutil doesn't come with Win Server 2012. I've tried installing Windows SDK and .Net SDK and not found a Gacutil executable. So I've tried to get in the dll into the GAC using powershell like this:
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall("D:\Pivotal.Gemfire.dll")
I've tried regsvr32 Pivotal.Gemfire.dll in various flavours
I've tried compiling and running the GacInstall executable at https://github.com/apache/geode-native/tree/develop/executables/GacInstall. It says Installation completed successfully. but when I try to run the service, or try powershell:
([system.reflection.assembly]::loadfile("D:\Pivotal.Gemfire.dll")).FullName
I get the same error.
I've tried a private assembly using runtime assembly binding
<runtime>
<assemblyBinding
xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Apache.Geode" publicKeyToken="null" culture="neutral" />
<codeBase version="9.1.1-build.2" href="file://Pivotal.Gemfire.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
and various flavours of name Pivotal.Gemfire, Apache.Geode.Client according to Implementing Shared Assembly but always the same error.
Any ideas? Thanks...
UPDATE: Make sure you have x86 and x64 bit C++ packages back to 2013 (for older versions of Geode Net client)
I downloaded the previous version of Geode, 9.0.7, called Gemstone.Gemfire.Cache.dll and got the same error, but that version included a Gemstone.Gemfire.Cache.xml in the same directory. If I took the xml file to my bin directory the error stopped and the service started properly.
So like this the problem is a redundant accompanying xml file to the dll. I fixed the issue by creating a new dummy xml file Pivotal.Gemfire.xml
<?xml version="1.0"?>
<doc>
</doc>
For me the marked answer did not work.
I had to download DependencyWalker which showed me why the Pivotal.Gemfire.dll was not working. One of missing DLLs was from:
Visual C++ Redistributable Packages for Visual Studio 2013
After installing 64x bit, application started to work.
This problem happened again with another install. The answer above using the xml file did not resolve it, it was resolved by downloading version 9.0.7 of the Native Client, Gemstone.Gemfire.Cache.dll and then running
.\gacutil /if C:\Gemstone.Gemfire.Cache.dll
which returned Assembly successfully added to the cache then removing the earlier version of the dll, but retaining the later version Pivotal.Gemfire.dll that I could not get into the GAC because of a strong name issue. This bizarre workaround of getting the earlier version of the dll into the GAC allows the GAC to find - and use - the later version...
This happened to me again with a Geode Native built locally, when it is run on a new Windows 10 install the dependency walker shows missing MSVCP140D.DLL VCRUNTIME140D.DLL and UCRTBASED.DLL as here
The D is related to having built the client in debug mode.
The problem is related to How can I install a Visual Studio C++ redistributable if it is missing? and the answer is either to get a release build of your dll, or to go to Visual Studio Installer, Modify, navigate to Individual components -> compilers, build tools, and runtimes, and check the MSVC v 140 VS 2015 C++ build tools
Yet another time this happened to me and I had to remove references and files to Apache Geode dll built as native client, then reference them all again.

Version conflict with a dll

I am developing an mvc application that uses Umbraco and NopCommerce.
Umbraco depends on dll called AutoMapper.dll with version 3.0.0.0.
NopCommerce depends on the same dll but with version 3.3.1.0.
So when I add the dll with version 3.0.0.0 then NopCommerce crashes.
When I add the dll with version 3.3.1.0 then Umbraco crashes.
So i somehow need to use the same dll with two different versions.
I have tried to add something like below to the web.config file:
<dependentAssembly>
<assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral"/>
<codeBase version="3.0.0.0" href="F:\Visual Studio test projects\UmbracoTest\UmbracoTest\bin\AutoMapper3000\AutoMapper.dll"/>
<codeBase version="3.3.1.0" href="F:\Visual Studio test projects\UmbracoTest\UmbracoTest\bin\AutoMapper3310\AutoMapper3310\AutoMapper.dll"/>
</dependentAssembly>
But with no luck.
Have anyone been in the same situation? Any advice on how to solve this?
Thanks! :)
No such luck, Umbraco simply doesn't support Automapper versions > 3.0. See this recent tweet conversation. How tied to NopCommerce are you? There are other options specifically for Umbraco, like Merchello or uCommerce.

VS2010 complaining about Microsoft.VisualBasic dependency

I've got a .NET solution that I've just upgraded from VS2008 to VS2010. It contains three web projects and two straight VB projects. The web projects all depend on (and have a reference to) one of the VB projects called BusinessLogic.
All projects are targeted at .NET 2.0, but VS2010 is raising the following build warning:
The following assembly has dependencies on a version of the .NET
Framework that is higher than the target and might not load correctly
during runtime causing a failure: BusinessLogic,
Version=1.0.4419.22315, Culture=neutral, PublicKeyToken=null. The
dependencies are: Microsoft.VisualBasic, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either
ensure that the dependent assembly is correct for the target
framework, or ensure that the target framework you are addressing is
that of the dependent assembly.
As far as I understand 8.0.0.0 is the correct version of VB for .NET 2.0, so why is this a warning? Is this something to worry about?
You have to go to menu Project|Properties and check the "References" Tab.
Check if the References you use are .NET 2.0 or higher.