Compilation error on consuming and building .NetStandard library using MS Build - asp.net

I have a couple of projects in my solution, migrated one of the class library to .netstandard(ModelLib) which is consumed by .net472 class library(serviceLib). The serviceLib is again referenced by another .net472 class library(apiLib). This apiLib is used in my asp.net website project.
Now, build works fine in VSStudio 2019, but fails when building using MS Build in test environment.
I get the following error and Build log says:-
c:\buildagent\xxxx\xxxx\web.config(186,0): error ASPCONFIG : Error ASPConfig: Could not load file or assembly 'apiLib' or one of its dependencies, the system cannot find the file specified.
The webconfig looks like this and line#186 is
<compilation debug="true" targetFramework="4.7.2">
<assemblies>
<add assembly="apiLib" />
</assemblies>
</compilation>
I checked the file in bin folder, the apiLib is missing.
Is there any .net version compatibility issues here?
Anybody faced similar issues and why apiLib is not copied into bin ? Is it something related to .NetStandard Project? Please help at the earliest..
Note: I haven't changed any package reference style of apiLib or similar libraries.
Thanks in advance.

Related

Why is my ASP.NET Web Site project targeting .NET Framework 4.6.1 when I have told it to target 4.8?

We have a large Visual Studio 2015 solution with several Web Site (as opposed to Web Application) projects and dozens of business-logic DLL projects. We were targeting .NET Framework 4.6.1, but I've now installed Visual Studio 2019 on my local PC and re-targeted all the projects to 4.8
When I build the solution using our existing PowerShell/MSBuild script, all the DLLs build successfully, but I get the following error when it comes to our first Web Site project:
C:\[omitted]_MyWebSite.metaproj : warning MSB3274: The primary reference
"C:\[omitted]\MyDLL.dll" could not be resolved
because it was built against the ".NETFramework,Version=v4.8"
framework. This is a higher version than the currently targeted
framework ".NETFramework,Version=v4.6.1".
Then later, when the compiler reaches some code on the site that tries to use the DLL:
c:\[omitted]MyController.cs(6): error CS0246: The type or namespace
name 'MyDLL' could not be found (are you missing a using directive or
an assembly reference?) [C:\[omitted]_MyWebSite.metaproj]
(This is just a sample reference error. In fact, all of the DLLs seem to suffer from this issue wherever they are used in the Web Site project.)
Relevant lines in the site's web.config file:
<location path="." inheritInChildApplications="false">
<system.web>
[omitted]
<httpRuntime targetFramework="4.8" requestValidationMode="2.0" maxRequestLength="10240" />
<compilation debug="true" strict="false" explicit="true" targetFramework="4.8">
I am using the following MSBuild.exe path:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe -maxcpucount:1 -verbosity:detailed
Looks like it's not enough to update the web.config file for Web Site Projects. You also have to update the target in the property pages. So in Solution Explorer, find your Web Site Project, right-click > Property Pages > Build > Target Framework > change to .NET Framework 4.8.
This is independent of the web.config file and resulted in a change in my .sln file from:
ProjectSection(WebsiteProperties) = preProject
[...omitted...]
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.6.1"
to:
ProjectSection(WebsiteProperties) = preProject
[...omitted...]
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8"

Reference required to assembly System.Runtime [duplicate]

I'm preparing a brand new ASP.NET MVC 5.1 solution. I'm adding in a bunch of NuGet packages and setting it up with Zurb Foundation, etc.
As part of that, I've added a reference to an in-house NuGet package which is a Portable Class Library and I think this is causing a problem on the build server.
TeamCity fails the build with:
The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0
I originally added the fix for the same or similar error when compiling the Razor web pages, that fix being in the web.config
<compilation ... >
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
However, the issue is unresolved.
To implement the fix, first expand out the existing web.config compilation section that looks like this by default:
<compilation debug="true" targetFramework="4.5"/>
Once expanded, I then added the following new configuration XML as I was instructed:
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
The final web.config tags should look like this:
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Adding a reference to this System.Runtime.dll assembly fixed the issue:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Runtime.dll
Though that file in that explicit path doesn't exist on the build server.
I will post back with more information once I've found some documentation on PCL and these Facades.
Update
Yeah pretty much nothing on facade assemblies on the whole internet.
Google:
(Facades OR Facade) Portable Library site:microsoft.com
The only way that worked for me - add the assembly to web.config
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
#PeterMajeed's comment in the accepted answer helped me out with a related problem. I am not using the portable library, but have the same build error on a fresh Windows Server 2012 install, where I'm running TeamCity.
Installing the Microsoft .NET Framework 4.5.1 Developer Pack took care of the issue (after having separately installed the MS Build Tools).
I had this problem in some solutions on VS 2015 (not MVC though), and even in the same solution on one workstation but not on another. The errors started appeared after changing .NET version to 4.6 and referencing PCL.
The solution is simple: Close the solution and delete the hidden .vs folder in the same folder as the solution.
Adding the missing references as suggested in other answers also solves the problem, but the error remains solved even after you remove the references again.
As for TeamCity, I cannot say since my configuration never had a problem. But make sure that you reset the working catalog as a part of your debugging effort.
It's an old issue but I faced it today in order to fix a build pipeline on our continuous integration server. Adding
<Reference Include="System.Runtime" />
to my .csproj file solved the problem for me.
A bit of context: the interested project is a full .NET Framework 4.6.1 project, without build problem on the development machines.
The problem appears only on the build server, which we can't control, may be due to a different SDK version or something similar.
Adding the proposed <Reference solved the build error, at the price of a missing reference warning (yellow triangle on the added entry in the references tree) in Visual Studio.
I was also facing this problem trying to run an ASP .NET MVC project after a minor update to our codebase, even though it compiled without errors:
Compiler Error Message: CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Our project had never run into this problem, so I was skeptical about changing configuration files before finding out the root cause. From the error logs I was able to locate this detailed compiler output which pointed out to what was really happening:
warning CS1685: The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'
c:\Users\Admin\Software Development\source-control\Binaries\Publish\WebApp\Views\Account\Index.cshtml(35,20): error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\meseems.webapp\68e2ea0f\8c5ee951\assembly\dl3\52ad4dac\84698469_3bb3d401\System.Collections.Immutable.DLL: (Location of symbol related to previous error)
Apparently a new package added to our project was referencing an older version of the .NET Framework, causing the "definition in multiple assemblies" issue (CS1685), which led to the razor view compiler error at runtime.
I removed the incompatible package (System.Collections.Immutable.dll) and the problem stopped occurring. However, if the package cannot be removed in your project you will need to try Baahubali's answer.
Install the .NET Runtime as well as the targeting pack for the .NET version you're targeting.
The developer pack is just these two things bundled together but as of today doesn't seem to have a 4.6 version so you'll have to install the two items separately.
Downloads can be found here: http://blogs.msdn.com/b/dotnet/p/dotnet_sdks.aspx#
On our Tfs 2013 build server I had the same error, in a test project.
with the main web project running on .Net 4.5.1.
I installed a nuGet package of System Runtime and added the reference from
packages\System.Runtime.4.3.0\ref\net462\System.Runtime.dll
That solved it for me.
I needed to download and install the Windows 8.0 (and not 8.1) SDK to make the error disappear on my TeamCity server.
https://developer.microsoft.com/en-us/windows/downloads/windows-8-sdk
i added System.Runtime.dll to bin project and it worked :)
I had this problem in a solution with a Web API project and several library projects. One of the library projects was borking on build, with errors that said the Unity attributes weren't "valid" attributes, and then one error said I needed to reference System.Runtime.
After much searching, reinstalling the 4.5.2 Developer Pack, and nothing working, I figured maybe it was just a version mismatch. So I looked at the properties of every project, and one of the very base libraries was targeting 4.5 while every other one was targeting 4.5.2. I changed that one to also target 4.5.2 and the errors went away.
I copy the file "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\system.runtime.dll" to bin folder of production server, this solve the problem.
For me I am using Microsoft visual studio 2019 and Windows server 2019 .
This web.config compilation part
<compilation debug="true" targetFramework="4.7.2">
Suddenly this error appeared during development and coding
I tried adding the assembly and reference its not solved the issue
This error solved after close and open visual studio and open project again .
install https://www.microsoft.com/en-us/download/details.aspx?id=49978 Microsoft .NET Framework 4.6.1 Developer Pack and add this line of code in Web.config file
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
For me helped only this code line:
Assembly.Load("System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Deleting the bin folder and rebuilding the solution worked for me.
In my case the .csproj file somehow was mixed up. Some 'Compile' elements were missing a 'SubType'.
<Compile Include="Control.cs" />
Fixed the issue by adding the "SubType" again:
<Compile Include="Control.cs">
<SubType>UserControl</SubType>
</Compile>
Removing the reference over the Nuget Package Manager and re-adding it solved the problem for me.

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.

asp server error ' Could not load file or assembly ' but the assembly is definitely there.

I am currently getting the following error. On a locahost website.
Could not load file or assembly 'MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Though, the reference is definitely there in the references folder and that dll is definitely on my local machine in the place it is pointing to. I have also tried deleting and re-adding the reference.
Does anyone know what would cause this error?
Also what is the assemblys manifest definition?
Thanks in advance for the help, I very much appreciate it.
in visual studio select the reference in the solution explorer then in the properties make sure the Specific Version property is set to false.
If you have an entry for this reference in the web.config, edit the file and remove the version information.
if you close visual studio and open the project file with a text editor, make sure in the project file the version of the assembly is not listed but only the name and type, so just remove the following:
, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
then it should work no matter if you are using the 6.5.5 or 6.5.4, as long as the code is using classes and methods available in both.
I have experienced the same situation and managed to fix the problem with these steps,
Read the error information carefully which provides helpful details to rectify the situation.
I wouldn't change the machine.config file.
As it says Application cannot find a reference to the assembly MySql.Web and the version it is trying to reference is Version=6.7.4.0.
Based on path you install MySql you will be able to find the correct assembly files, ex :
C:\Program Files\MySQL\Connector NET 6.7.4\Assemblies\v4.0\MySql.Data.dll
Copy that file to bin folder. (I would copy all the files in C:\Program Files\MySQL\Connector NET 6.7.4\Assemblies\v4.0\ folder to bin folder)
Hope this helps! Thanks
I have encounter the same problem very few days ago , you get this error when you have build your some DLL with earlier version and now you have change the dependent DLL version but had not build the DLL again . Please check if you have any component which was build on the earlier version . While we build any DLL , DLL it self in the manifest add all the dependency information so that it can load all of them when required . So if you remove that version of DLL you need to recompile all the component and then use
This problem persists also in newer version of MySql.Data. Just change the version from App.config file:
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.6.5.0" newVersion="6.6.5.0" />6.7.4.0
to oldVersion="6.6.5.0"
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="6.6.5.0" newVersion="6.7.4.0" />
I had this in an older asp.net 2.0 website on a new machine. In my case, the MySql assembly from the GAC could not be loaded because it was .Net 4.0. Assembly redirect in web.config did not work. I fixed it as follows:
Download the specific version of MySql.Web and MySql.Data from nuget:
https://www.nuget.org/api/v2/package/MySql.Web/6.5.4
https://www.nuget.org/api/v2/package/MySql.Data/6.5.4
Open the downloaded packages with a zip tool (e.g., 7zip) and extract the .Net 2.0 assemblies into the bin directory of the malfunctioning asp.net site.
I was getting the same error and the file absolutely existed.
If you see a SGEN next to your error, you can try this:
In the project properties window go to Build and in the Output section go to the Generate serialization assembly dropdown. Change the value Auto to Off and Build again.
You can set it back to auto if you need it.
In some situations, it depends on bindingRedirect attributes in web.config file of the project. In my case, I had two version: olderVersion and newVersion. I just switched those values and it solves the problem.
WARNING: Be sure that the newer version is referenced into web.config assemblies' tag file just as :
<add assembly="$AssemblyName", Version=$NewVersion, Culture=neutral, PublicKeyToken=$KeyToken/>

Microsoft ASP.NET ReportViewer Parser Error

I've been using a MS ReportViewer component in a website for a while now, but recently I've been getting the error shown below.
Parser Error Message: The base class
includes the field 'xyz', but its
type
(Microsoft.Reporting.WebForms.ReportViewer)
is not compatible with the type of
control
(Microsoft.Reporting.WebForms.ReportViewer).
<rsweb:ReportViewer ID="xyz" runat="server" Width="100%" Font-Names="Verdana" Font-Size="8pt" Height="400px" ProcessingMode="Local" ShowExportControls="false">
Now, I get this error in Visual Studio as well as in production. I have the ReportViewer Redistributable installed in production.
Am I somehow missing a reference in my project, or something?
I discovered the answer: Somehow the reference to version 9 of Microsoft.Reporting.WebForms got switched to version 8. This caused the error. So deleting the reference and adding in the correct version of the reference seems to have fixed the problem.
Edit:
Well, according to the previous version of the .vbproj file, it was a reference to 9, despite that the project references properties screen told me 8. In short I'm not really sure what managed to get screwed up, but it seems to be working now.
If anyone has experienced this or has some insight, please contribute.
Following a clean install, my project didn't compile because the reference to the dll was broken, so I deleted it and added it again, then the web page where the ReportViewer is used gave a parser error:
The base class includes the field 'rprtReportsViewer', but its type (Microsoft.Reporting.WebForms.ReportViewer) is not compatible with the type of control (Microsoft.Reporting.WebForms.ReportViewer).
I found a reference on the webpage with version number different to the one I had just added:
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
I changed the version to 9.0.0.0, and this time got a compiler error when I refreshed the page:
CS0433: The type 'Microsoft.Reporting.WebForms.ReportViewer' exists in both 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\8.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll' and 'c:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll'
I then searched the solution for "Microsoft.ReportViewer" and found more references in compilation.config:
<add assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
I changed the version numbers here too and it stopped the errors
You may also need to Remove from \bin files:
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll
Microsoft.ReportViewer.WinForms.dll
I just moved them into a sub directory.
Check your page rdlc version like
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
Having the same issue. Clean Windows 2008 Server install with SQL Server 2005 and SQL Reporting. The server hosts the site. Installed ReportViewer 2008 SP1. Web.config references version 9.0.0.0.
The same error message comes up: The base class includes the field but its type (Microsoft.Reporting.WebForms.ReportViewer) is not compatible with the type of control (Microsoft.Reporting.WebForms.ReportViewer).
Searched online and lots of people experience the same issue. Some people suggest manually editing project file.
I managed to fix it by setting Specific Version = True (Version=9.0.0.0) in the Solution Explorer->[Web Project Name]->References->Microsoft.Reporting.WebForms->Properties.
In one of the environments we also found Microsoft.Reporting dlls in the web bin folder. And, they were conflicting with the dlls registered in the GAC. Deleting of the dlls solved the issue.
I had this problem on a Production server. I installed the correct version of ReportViewer and made sure all the references in the project were pointing at the correct version. However, I was still getting errors.
Eventually I solved the problem by going to 'Temporary ASP.NET Files' and deleting the files for my app. To do this you'll need to stop the app first. This then solved the problem. On DEV servers I had not encountered this problem because after installing ReportViewer I re-started the machine.
Hope this helps someone. I pulled a lot of hair out before I solved this particular 'challenge'.
References -> (Microsoft.ReportViewer.WebForms), click the right mouse button.
The Specify Version option, leave it as false.
After that, just save and run again.
I came across the same error. What worked for me was to delete the reference Microsoft.ReportViewer.WebForms and add it again.

Resources