ASP.NET Compiler complaining of mismatching framework versions with MiniProfiler - asp.net

I have an MVC3 project that I upgraded from VS2010 to VS2012. The project also has a reference to MiniProfiler. Our application compiles and runs fine in VS2012 without any warnings/errors. Both assemblies load fine when running with IIS Express. When using the ASP.NET Compiler tool, however, I get the following warning:
Microsoft (R) ASP.NET Compilation Tool version 4.0.30319.17929 Utility
to precompile an ASP.NET application Copyright (C) Microsoft
Corporation. All rights reserved.
(0): 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: MiniProfiler,
Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3. The
dependencies are: System.Data.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089. 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.
We don't have an explicit reference to System.Data.Linq. Up until the update to VS2012, we didn't have any errors. The MiniProfiler version is indeed targeting .NET 4.0 (as is our application). What could be causing this warning?

I was finally able to fix it with a tip from this answer. I added the following <add> line in the web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<!-- etc... -->
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<!-- etc... -->
</assemblies>
</compilation>
<system.web>
</configuration>

Did you changed targetFramework inside Web.confing?

Related

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.

.NET 4.0 DataAnnotations GAC/EntityFramework conflict

I'm trying to build an ASP.NET web site for Microsoft .NET 4.0 using Entity Framework 6. The website is explicitly targetting .NET 4.0 in web.config:
<compilation debug="true" targetFramework="4.0">
, IIS Express' application pool in applicationhost.config also targets .NET 4.0:
<add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
When the site is launched, a number of CS0433 compiler errors is shown, ones like below:
error CS0433: The type "System.ComponentModel.DataAnnotations.Schema.TableAttribute" exists in both "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" and "c:\Users\%username%\AppData\Local\Temp\Temporary ASP.NET Files\vs\e798ee36\2b3f5a24\assembly\dl3\fd34a92a\0052703a_0990d101\EntityFramework.DLL"
As far as I remember, there should be no System.ComponentModel.DataAnnotations assembly in .NET 4.0, or at the very least it shouldn't contain classes like TableAttribute, KeyAttribute etc. The only lead I have is the bottom line of error page, which says
Microsoft .NET Framework, version:4.0.30319; ASP.NET, version:4.6.1055.0
however, I don't know how to change specifically ASP.NET version for a website (of course, if that's the problem's source).
Have you tried setting the compilation batch to false?
<compilation debug="false" batch="false">
I'm assuming you've got code in your App_Code folder (likely your Entity Framework classes at the least?).
Now you could move your code out of there, and precompile everything so that you deploy the website assembly and not any source files.
Otherwise, you really need to look at your projects and ensure that nothing is referencing System.ComponentModel.DataAnnotations.
Also, check any web.config in the project at the root, or in the App_Code folder(s) and make sure there is no
<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
under system.web/compilation/assemblies. If there isn't, you could even try putting in
<remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
e.g.:
<compilation>
<assemblies>
<remove assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
You can also check to make sure it's running the earlier version of ASP.NET so that it picks up the version of the DataAnnotations assembly that doesn't have the Schema attribute (as the 4.5+ framework version does):
<configuration>
<system.web>
<httpRuntime targetFramework="4.0" />
</system.web>
</configuration>
Hey Can you check your project.Please check there should not be two model with same properties.Model can also be entity framework class model
Check if all NuGet packages for your project are updated or if there are any installed that you don't want.

Parser Error Message: Could not load file or assembly. But the assembly is there

I do not understand from where this problem comes. I have the correct assembly in the Bin, the same is correctly referenced in the web.config
<compilation targetFramework="4.5" debug="true">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Telerik.ReportViewer.WebForms, Version=8.1.14.804, Culture=neutral, PublicKeyToken=A9D7983DFCC261BE"/>
</assemblies>
</compilation>
....
<httpHandlers>
.........
<add path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=8.1.14.804, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" validate="true"/>
</httpHandlers>
the particular feature object of the error is working on my developing machine but on the production server I get this error!
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load file or assembly 'Telerik.Reporting, Version=8.1.14.804, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line%70<td%class="leftGridColumn"> </td>
Line%71:<td%class="centerGridColumn">
Line%72<telerik:ReportViewer%ID="ReportViewer1"%runat="server"%Width="100%"%Height="660px"%ShowExportGroup="False"%
Line%73:</td>
Line%74:<td%class="rightGridColumn"> </td>
Any hint will be really appreciated I do not know what else do do to solve this problem.
The only thing I can think of is 'Are you sure you are using the correct/compatible version of the .Net Framework?'. I had a problem a while back when using Asp.Net MVC where it didn't like 4.5, so i had to create a 4.0 project.
EDIT
Just found this on an old blog:
The original warning you receive explains that you should register the handler for the web report viewer in the httphandlers section in the web config. However if you're hosting the application in IIS7, there is a different section to add the handler to, namely the <system.webServer>\<handlers> section:
<system.webServer>
<handlers>
<add name="Telerik.ReportViewer.axd_*" path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=3.2.9.1211, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" preCondition="integratedMode,runtimeVersionv2.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
"it clearly states that it cannot find a necessary assembly you're referencing. During the installation of Telerik Reporting on your machine, the Telerik assemblies were added to GAC. When deploying a Web Site project the assemblies from the GAC are not copied automatically, so you need to copy the assemblies manually from the installation’s Telerik Reporting /bin folder to the bin folder of your application on the server. Full step by step instructions on deploying are included in the Deploying Applications using Telerik Reporting help article."
Here's the link: http://www.telerik.com/forums/web-reportviewer-error

Entity Framework works on Local Server but not Remote

Ok so I have a website that uses ASP.net mvc, the problem I am having is with Entity Framework. I added all the references and got it to run on my local machine but when I publish it I get the following error.
System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I have double checked my references and I have EntityFramework.SqlServer and System.Data both added into my project. The connection string I use to connect to the data base and declare the service provide is below.
<connectionStrings>
<add name="[dataConnection]" connectionString="Data Source=[ip of host machine];Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Name we just have the name of the data base, this is also used in my web.debug.config
<connectionStrings>
<add name="[dataconnection]"
connectionString="Data Source=.;Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
I am pretty new to this entire thing and was just handed someone elses code so I am trying to learn on the flow. This is my first encounter with this so any direction would be appreciated.
I had the same problem in my integration test assembly (i'm using ms visual studio unit testing framework for this) and i've solved it by adding EF assemblies to deployment items in .testsettings file.
I've installed EF 6 alpha using Package Manager Console using:
Install-Package EntityFramework -Pre
Here is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
My connection string (i'm setting it in code): server=.\SIN;initial catalog=IntegrationTests;User ID=user;Password=pass;MultipleActiveResultSets=true;
I've looked at the EF assembly reference properties to see if they are set to "Copy Local" = True.
And finally i've checked out TestResults/../Out folder and found that there is no EntityFramework.SqlServer assembly there (SqlProviderServices class resides in it).
So i've just added both EF 6 assemblies to my deployment items and now everything is ok
You can try to copy EntityFramework.SqlServer assembly to your web server directory to see if it works.
Maybe this link can be helpful
P.S:
Make sure you don't have a reference to System.Data.Entity, because you'll be using one from GAC. EF 6 Alpha assemblies is not installed in GAC when you install them with Nuget. Target framework should be .NET 4.5.
Sorry for my bad english.
A question: which EF version?
Check your IIS pool .NET version... It should be the one that points to the .NET version of your published project... The assembly of EF should be in the .NET framework folder under Windows directory (AKA GAC)

visual studio 2k8 (and 2k10) cannot compile web application when gac assemblies are moved into global web.config

I have numerous ASP.NET 3.5 web applications with verbose application-level web.config files which I wish to slim down and make more readable.
Visual Studio 2010 has just arrived and has already started "cleaning up" various sections of the web.config - so now is a perfect time for me to continue the good work and do the same in other areas of the web.config file.
Currently I have several third party assemblies all happily registered in the GAC, these are then referenced in each application-level Web.Config see below;
<configuration>
<system.web>
<compilation defaultLanguage="C#" debug="true">
<assemblies>
<add assembly="AjaxControlToolkit, Version=3.0.30512.20315, Culture=neutral, PublicKeyToken=28F01B0E84B6D53E"/>
<add assembly="aspNetEmail, Version=3.5.2.0, Culture=neutral, PublicKeyToken=BC571E8DA1C1F543"/>
<add assembly="aspNetDns, Version=3.0.0.0, Culture=neutral, PublicKeyToken=BC571E8DA1C1F543"/>
<add assembly="Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
</system.web>
</configuration>
I have moved the above compilation-node into the global web.config file located at Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config - and the application runs just fine under IIS7 i.e. the application has no trouble finding these GAC'd assemblies.
however when I now compile (shift+ctrl+b) my web application in visual studio 2k8 or 2k10 I'm getting the familiar error "The type or namespace name 'aspNetDns' could not be found (are you missing a using directive or an assembly reference?)"
What do I have to do to get visual studio to recognise the whereabouts of these GAC'd libraries? I tried copying them into windows\system32 but no joy there...
help! :)
NB: I have also tried working with the machine.config but still no luck
Solved it.
I needed to edit the global web.config in the x86 directory (as well as the x64 version) - the x86 version is obviously the one Visual Studio was looking at whilst compiling the app, whereas IIS was looking at the x64 version of the global web.config when running the app.
Drag / drop the assemblies to c:\windows\assembly on your local machine where you are recompiling.

Resources