Building Core2.0 project in Visual Studio Team Services fails with numerous assembly import errors - asp.net

I have Build Definition
.NET Core Restore
.Net Core Build
.Net Core Test
.Net Core Publish
Publish Artefact
While I was using Core1.1 it worked without any issue. But after upgrading project to Core2.0 it fails with multiple errors like
error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Users\buildguest\.nuget\packages\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Threading.Tasks.Parallel.dll' and 'C:\Users\buildguest\.nuget\packages\system.threading.tasks.parallel\4.3.0\ref\netstandard1.1\System.Threading.Tasks.Parallel.dll'
error CS0433: The type 'TargetFrameworkAttribute' exists in both 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
error CS0518: Predefined type 'System.String' is not defined or imported
Solution is perfectly building locally. I tried to add task Use .NET Core runtime 2.0.0 in the beginning but without any success.

You should add .NET Core Tool Installer task at the beginning of the build steps. Then install the SDK not only runtime. Then save your build definition and queue again.

Related

System.Net.Http not found after migrating from .netcore 2.1 to asp.net 4.7.2

I recently migrated my project from .netcore 2.1 to asp.net 4.7.2, because of some 3rd party .dll. The solution builds and runs locally. It also builds on our dev environment in TeamCity. However, it does not work in Azure. On checking the logs I get the following error:
[ERR] An unhandled exception has occurred while executing the request.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
The file does exist! After some research I came upon this post: Single-name references are removed by the SDK when targeting .NET Framework 4.7.2 and referencing a package with the same assembly
I removed the System.Http.Net reference hoping it will use it from the framework, same error. Next, I tried the workaround stated there:
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.2.0">
<ExcludeAssets>All</ExcludeAssets>
</PackageReference>
</ItemGroup>
Same error.
Any help or troubling shooting ideas would be welcome

ASP 5 MVC 6 (RC1) - Web API with EF 6 works locally but not deployed

I have a Web API I created in ASP 5 MVC 6 (FULL CLR). The web API references a standard .net class library, which has the entity framework 6 NUGET package installed. If I launch the web api locally (IIS express) and then try to run a method which contacts the database, everything works fine.
When I deploy the web API (I set it up in IIS), using the "Publish" command, to my DEV server (Windows Server 2012) and try to contact the same method, but on the server, I get the following exception (any other method that doesn't touch the database works):
{
"$id":"1",
"ClassName":"System.IO.FileNotFoundException",
"Message":"Could not load file or assembly 'EntityFramework,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
or one of its dependencies. The system cannot find the file specified.",
"Data":null,
"InnerException":null,
"HelpURL":null,
"StackTraceString":"
at CMAllocation.Web.Data.InvestorRulesRepository..ctor()\r\n
at CMAllocation.Web.CMAllocationWebApi.Controllers
.InvestorRulesController.GetInvestors()
in E:\\CMAllocation\\WebServices\\CMAllocationWebApi
\\Debug\\approot\\src\\CMAllocation.Web.CMAllocationWebApi
\\Controllers\\InvestorRulesController.cs:line 45",
"RemoteStackTraceString":null,
"RemoteStackIndex":0,
"ExceptionMethod":
"1\n.ctor\nCMAllocation.Web.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null\nCMAllocation.Web.Data.InvestorRulesRepository\nVoid .ctor()",
"HResult":-2147024894,
"Source":"CMAllocation.Web.Data",
"WatsonBuckets":null,
"FileNotFound_FileName": "EntityFramework, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089",
"FileNotFound_FusionLog":
"WRN: Assembly binding logging is turned OFF.\r\n
To enable assembly bind failure logging, set the registry value
[HKLM\\Software\\Microsoft\\Fusion!EnableLog] (DWORD) to 1.\r\n
Note: There is some performance penalty associated with
assembly bind failure logging.\r\n
To turn this feature off, remove the registry value
[HKLM\\Software\\Microsoft\\Fusion!EnableLog].\r\n"
}
Any help would be appreciated.
UPDATE I can clearly see the EF 6 dll's in the approot/packages folder:
Your server is missing 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
Build on the server with msbuild.
Run NuGet restore. Dave Ebbo has a good article. It is nuget restore from the cmd line.
If that doesn't work, install the EntityFramework package into the GAC on your server.

Dependency on the framework assembly "System.Runtime, Version=4.0.10.0," which could not be resolved in the currently targeted framework

TFS 2013 - Build: ASP.Net 4.5.1 website I get this error:
warning MSB3268: The primary reference "C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll"
could not be resolved because it has an indirect dependency on the framework assembly
"System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which
could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5.1". To resolve this problem, either remove the reference
"C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll" or retarget your application to a framework
version which contains "System.Runtime, Version=4.0.10.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a".
All projects and site was 4.0 initially using Unity 1.0.0.0. I upgraded it to 4.5.2. Also the MyProj1 in the error above is referencing Unity and I upgraded it to 3.5.1 as well.
Read this: https://unity.codeplex.com/workitem/12756
The build server already have the updated 4.5.2 pointed in the workaround.
So I downgraded to 4.5.1 but still getting the error.
Solution builds fine locally via Visual studio 2013.
The stand alone class libraries project build in TFS fine but when MyProj is added as a reference to my Website, that's when it fails.
Any ideas?
Do I need any web.config changes other than TragetFramework settign while upgrading?
I had to upgrade my Unity to 3.5 due to my project's dependency on some other project and this error came again. This time, finally got it fixed.
This one helped me: http://devsilos.blogspot.com/2014/10/msb3268-while-targeting-aspnet-web-site.html
Solution I copied all the files that build was complaining about from:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Facades
To
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2
Here's the explanation from the link above in case it goes down for any reason in future:
A deeper inspection revealed the following interesting fact:
aspnet_compiler for some reason does not take into account the .dll-s
that reside under the Facade directory of 4.5 assemblies (C:\Program
Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades). It looks
only under C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5
As a result the whole thing failed since both System.Threading.Tasks
and System.Runtime .dll-s were under the Facades directory and not
inside the v4.5.
Now the solutions:
Just simply copy the missing .dll-s from Facade to the v4.5
directory.
Set the TargetFrameworkMoniker to 4.5.1 in the .sln file. The exact
syntax is as follows: TargetFrameworkMoniker =
".NETFramework,Version%3Dv4.5.1".
What happens in this case is that the aspnet_compiler does not
recognize the exact version of the required framework and tries to
use the GAC wherever it can. If 4.5 is the highest version installed
on the build machine I believe it should work.
Actually sorry I don't think "assemblyBinding" would help.
It seems like a known bug. It has not been resolved. Using Unity 3.5 you can target .NET 4.5.1 but not 4.5.2.
So one option would be to re-target to .NET 4.5.1 and see if the problem goes away, if that's an option.
p.s.
Also you can try .NET Framework 4.5.2 Developer Pack. But some have mentioned it did not work.
We recently ran into a similar problem with a site that was upgraded to target .NET 4.5, and initially followed the solution in gbs's answer.
In our case, we had several warnings following this pattern:
<project name>.metaproj : warning MSB3268: The primary reference "<project reference>.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "<project reference>.dll" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
We then discovered that if you create a new web site targeting 4.5.x (File > New > Web Site...) and select the ASP.NET Empty Web Site template, the package Microsoft.Net.Compilers is included. Adding this package to our site resolved the issue without the need to touch the reference assemblies.
Of the original two solutions, copying the files caused the build to succeed but presented maintenance concerns, and changing the TargetFrameworkMoniker (to 4.5.3 rather than 4.5.1) produced a different build error and was a brittle solution.

Oracle.ManagedDataAccess The system cannot find the file specified

In my website project built on .net 3.5, when I add reference to the Oracle.ManagedDataAccess.dll by adding this in the web.config
<add assembly="Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
it give this error
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.
This error comes at .net version 3.5
The solution is to upgrade the .net version to .net 4.0 or above
Upgraded my project version to .NET 4.8 from .NET 4.5.2 and then
Installed the OracleManagedDataAccess nuget package into the solution (seems it wasn't installed)
This resolved the error.

ASP.NET Web Api nightly builds doesn't run on server

I get this error message on my server:
Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
RouteTable.Routes.MapHttpRoute(...)
I use Nuget to download the latest nightly build of Microsoft ASP.NET Web Api.
It's seems like a bin/gac problem but I'm not sure.
An older version of System.Web.Http was installed in the GAC.
gacutil /uf system.web.http
That fixed it.

Resources