assembly file not found in asp.net project - asp.net

I am trying to use the devexpress.xpo assembly in my asp.net project but I am having trouble adding it to my project. I have added an assembly reference in my applications web.config(see below) and when I run the application on my development machine (vs 2010 iis express 7.5) everything works fine. However when I deploy the application to our production server (iis 6.0) I get the following error:
Could not load file or assembly 'DevExpress.Xpo.v9.1' or one of its dependencies. The system cannot find the file specified.
The development machine has the assembly installed in the GAC but the production server has not. I have added the DevExpress.Xpo reference via visual studios add reference function so the DevExpress.Xpo.v9.1.dll file is copied to my applications bin folder.
My web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="DevExpress.Xpo.v9.1"/>
</assemblies>
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
</configuration>

Search applications bin folder on production server for DevExpress.Xpo and DevExpress.Data dlls. You need to have both dlls there since DevExpress.Xpo won't work without DevExpress.Data.
Also, look here for discussion about "choosing" between Bin folder and GAC dlls:
http://www.devexpress.com/Support/Center/p/Q230929.aspx

Copy assembly files (Web.config's entries registered within the "assemblies" section http://msdn.microsoft.com/en-us/library/bfyb45k1.aspx) required for each used product / suite ("Deployment - General Information") within the GAC or "Bin" folder.
This approach is common for any 3-rd party tools http://msdn.microsoft.com/en-us/library/ms178610%28v=vs.80%29.aspx.

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.

Server Error in '/' Application. This type of page is not served

I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.

asp.net Compilation Error (mysql.data)

i have an error when trying to start default.aspx.
Compiler Error Message: CS0433: The type 'MySql.Data.MySqlClient.MySqlConnection' exists in both
'c:\Windows\assembly\GAC_MSIL\MySql.Data\6.3.6.0__c5687fc88969c44d\MySql.Data.dll' and 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\elwazefa\fd12d8de\3446c68c\assembly`\dl3\dc121b8b\00d6e0c3_62aacb01\MySql.Data.CF.DLL'`
i am using asp.net 3.5
what is the problem, thanks
It looks to me like you have references to both the Compact Framework and the standard framework MySQL libraries in your project. You need to remove the references to the ones that have .CF in their filename.
Check your web.config file assemblies section for multiple references:
<compilation>
<assemblies>
...
</assemblies>
</compilation>
If there is more than one then remove it (the one not in the GAC, I would say off-hand.)
Also, as #Abe suggests, delete the temporary files under the following path:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\

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