Web.Config Assembly/Reference Issue - asp.net

Today I had to re-create my web.config file, and have lost my previous code.
I have my database connection and roles working fine, however, my assemblies never seem to work... In my back-end code, I always get the error
The type or namespace name 'Insert Here' does not extist in the namespace 'Insert Here' (are you missing an assembly reference?)
My current config file's assembly section has been created by Visual Web Developer by using the Add Reference option:
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="mscorlib"/>
<add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="*" />
</assemblies>
</compilation>
---rest of code here---
Just incase it means anything, the tutorials I followed when making my database Membership friendly directed my to the aspnet_regsql.exe in the C:\Windows\Microsoft.NET\Framework\v2.0.50727 directory, but the versions in my web.config are 4.0.0.0. Could this have something to do with it? Should I use the exe found in the v4.0.30319 folder?
If someone could please help me try to get this fixed... I really can't make any progress on my site anymore as all non-database stuff is done...

I figured there was something wrong with my web.config files, so I just made a new website, copied everything over from the original folder and it works.
I know it may not have been the best solution, but it took maybe 10 minutess, far less than the time I've already wasted.

Related

Visual Studio 2022 - could not load file or assembly Microsoft.Build.Tasks.v4.0. The system cannot find the file specified

So I'm back from a nice Christmas break - and completely stymied. When I try to build my Visual Studio 2022 solution I get this message:
Build (web): Could not load file or assembly 'Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I also get this in VS 2019 too. My website is ASP.NET webforms - I've got two other MVC websites which build and run perfectly. Here is the relevant section of my web.config file:
<compilation debug="true" strict="true" explicit="true" batch="false" targetFramework="4.7.2">
<assemblies>
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Printing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
I've just spent 3 hours reading through blogs like this StackOverflow one:
Could not load file or assembly 'Microsoft.Build.Framework'(VS 2017)
I've tried restarting Visual Studio, and even turning my computer off and on again. I've commented out the assembly lines in the web.config file shown above. I went into Nuget package manager and added Microsoft.Build.Framework to see if this would help (it didn't).
Here's what the project references look like:
I've had this sort of problem on numerous other occasions, and usually sorted it fairly quickly - but not this time. I know little about building projects - I just want Visual Studio to do it all for me!
Can any kind person help please?
So I've at least got this in a working state - here's an update for anyone else facing this nightmare (and who, like me, doesn't fully understand what building involves).
I still have the build error, but if I right-click on a .aspx file to view it in a browser this now works (before it gave a compilation error). To reach this state I removed any references to any Microsoft.Build libraries that I had set in Nuget. I don't know whether this helped or not!
Of course I can't debug (because this requires a build), so this is at best a temporary fix, but at least I can do some work on the website.
Someone also mentioned this page, which gives a good summary of the opacity of the build process:
How do references work in ASP.NET WebForms websites (not web applications)?

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

The type or namespace name 'Linq' does not exist in the namespace 'System'

I have a wcf service hosted in a website in IIS and I seem to have this issue.
In my web.config I have this:
<system.web>
<compilation>
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
</system.web>
All projects in the solution target framework 4.0.
LE: I get the error when I try to import System.Linq;
using System.Linq;
Solution: It seems that the web config should be:
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
Do you have a code file in your site with either Imports System.Linq (VB) or using System.Linq; (c#)?
Seems like the simplest answer is that it is a typo. Maybe the namespace should be corrected to System.Data.Linq.
Edit:
System.Linq should be a valid namespace, as it "provides classes and interfaces that support queries that use Language-Integrated Query (LINQ)." (http://msdn.microsoft.com/en-us/library/system.linq.aspx). It is also imported by default in the system-level web.config.
So, not sure what is happening here if it is not related to my suggestion above. Maybe something wrong in your machine.config or system-level web.config?
Edit 2:
I find it strange that you adding the System.Core assembly at this level. I believe this is the assembly that includes the System.Linq namespace. Maybe removing it would help?
Edit 3:
System.Linq is imported by default in the machine-level web.config. You can remove the line in your code file.
Sometimes it "disappears" just for the fun of it. If you don't need it just delete it.
Else right click your website in the solution explorer and add a reference to it.
I had no Linq methods on my Controller (Count, Where, toList, etc...). Adding the namespace:
using System.Linq;
fixed the problem for me. Maybe will help someone in the future...
I solved this problem by adding the System.Linq namespace to the namespaces in the Views\Shared\Web.config file, e.g, as below, 2nd from the bottom, above the WebApplication1 namespace.
Note, this is in the Web.config in the Views folder and is not the web site's main 'Web.config`.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="System.Linq" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
</system.web.webPages.razor>
Another thing to check is is your .csproj file, specifically these items:
<TargetFrameworkProfile>Profile47</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
If you don't have a folder for the Profile indicated, you might need to manually change it to one you do have. You might also be able to download the target from https://www.microsoft.com/net/download/visual-studio-sdks.
Unfortunately, my colleague had this happen with an old-style PCL project (profile-based PCL), so he wasn't able to go download the .NET Portable target, but I had to give him the DLLs out of my functioning folder (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile47).
I had the same error but my web app was running on framework v2.0. Changed my application pool from v2.0 to v4.0. all working...happy days
the problem is you didn't add
debug="true|false" targetFramework="4.0"
in compilation tag.
The solution for me was to:
Go to: Tools > Nuget Package Manager > Manage NuGet Packages for Solution
Install the System.Linq package.
Deleting the hidden .vs folder and restarting Visual Studio fixed it for me.

MVC 3 project rejects requests for Razor views with CS0103: The name 'model' does not exist

I have and MVC3 project that once upon a time was an MVC2 project. I've been developing it using IIS express to test.
Now I deployed it to IIS proper on my machine, jiggled some web.config settings, and messed around for an hour getting the razor build provider to be registered, which must not be done right because the new project template doesn't include a line adding that build provider in the web.config.
At any rate, any time I go to a strongly-typed Razor view I get this:
Compiler Error Message: CS0103: The name 'model' does not exist in the current context
Source Error:
Line 1: #model Cairn.Cartography.Features.Peak
Any thoughts on what is going on, and how I might fix it without firebombing this box and looking around for my windows install cd? :)
I was missing:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
in this part of my web.config file:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="Cairn"/>
<add namespace="Cairn.UI.Web"/>
<add namespace="Cairn.UI.Web.Helpers"/>
</namespaces>
</pages>
</system.web.webPages.razor>
I haven't the foggiest what this means or why it matters, or why it is absent from the web.config generated for a brand new project, but it works.
? Oh well
yes.. reinstall asp.net MVC3 again
either get the MSI file from here: http://go.microsoft.com/fwlink/?LinkID=208140
or use Web Platform Installer from here: http://www.microsoft.com/web/gallery/install.aspx?appid=MVC3

Failure to compile Linq Method in App_Code

I've been scratching my head for what seems like ages. I'm sure its really simple to fix but I can't see it.
I have a class in App_Code that uses a bit of Linq.
var siteMap = SiteMapWrapper.BuildSiteMap(true);
var currentTopLevelParent = siteMap.Single(s => s.IsActive);
if (currentTopLevelParent != null)
I've developed this locally and all works fine. When I transfer to IIS hosting the same class fails to compile. I receive:
does not contain a definition for 'Single' and no extension method 'Single'
accepting a first argument of type 'SiteMapWrapper' could be found (are you
missing a using directive or an assembly reference?)
I confirmed that the virtual dir is running .NET 2.0 as it should. I also confirmed that the correct assemblies are being loaded in the web.config.
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
I've tried adding namespaces directives in web.config also but no luck. Can anyone think of anything else to try?
Many thanks.
I think you will find that the server does not have 3.5 installed.
Add using System.Linq; to the top of the .cs file.
Also, make sure that SiteMapWrapper implements IEnumerable<T>.
EDIT: I didn't notice that it works on the local machine.
Make sure that the server has the correct versions of all of the dependent assemblies.
LINQ actually requires .NET 3.0 (3.5 is better), not 2.0. Make sure the AppPool is configured appropriately.
Change the Build Action Property of your .cs file from Content to Compile.
See this article for more info.

Resources