System.Net.Http missing? - asp.net

I am trying to run Test.aspx:
<%# Page language="c#" EnableViewState="true" ContentType="text/html" Async="true" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E )
{
RegisterAsyncTask(new PageAsyncTask(BindData));
}
private async System.Threading.Tasks.Task BindData()
{
Response.Write("Hello?<br /><br />");
using (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient())
{
Response.Write(await httpClient.GetStringAsync("http://www.google.com"));
}
Response.Write("<br /><br />Is this thing on?<br /><br />");
}
</script>
and getting this error:
Test.aspx(14): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
The System.Net.Http.dll assembly is in
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies
and in IIS Manager the Basic Settings' Application Pool is ASP.NET v4.0 (Integrated). Has anyone run into this?
UPDATE: I installed .Net 4.5.2 and added the following web.config
<configuration>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation>
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>
and it worked.

To resolve this I had to add
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
and
<httpRuntime targetFramework="4.5.2" />
to the web.config

I've tried this highly suggested solution (I found this as accepted answer in many similar questions here in SO)
on Web.Config write this and rebuild the solution
<system.web>
<compilation debug="true" targetFramework="4.0" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
But unfortunately, I've no luck with this. At last, I've found a solution which works for me and saved my day :)
Right-click the References folder > Add Reference...
Expand Assemblies on the left side of the window and select Framework.
Scroll to and select System.Net.Http in the list of assemblies.
Make sure the box next to System.Net.Http is checked, then click
OK.
Rebuild the project.

In my case, the issue started occurring after upgrading to .NET Framework 4.7.2. I found out that Nuget package for System.Net.Http is no longer recommended. Here are workarounds:
Single-name references are removed by the SDK
Nuget package for System.Net.Http on .NET Framework 4.7.2 and newer versions

To resolve my problem, Just add this in webconfig.
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
and
<httpRuntime targetFramework="4.5" />

Related

In mvc4 i am using grid view but it is showing error

#model IEnumerable<gridview.Models.emp>
#{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.All);
}
but here it is showing error like
Error 1 The type or namespace name 'WebGrid' could not be found (are you missing a using directive or an assembly reference?)
c:\Users\anand.kumar\Documents\Visual Studio 2013\Projects\gridview\gridview\Views\Home\Index.cshtml 3 20 gridview
Add the Reference System.Web.Helpers to your project and Rebuild the project.
Try this:
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
has to be added in web config, under system.web section, withing compilation tags so it will look like:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
OR
1) Open NuGet Package Manager in Visual Studio and search “microsoft-web-helper” and install.
2) After installing it open web.config in your solution and change connectionStringName parameter for DefaultMembershipProvider, DefaultRoleProvider ve DefaultSessionProvider (if you do not, you might encounter 'DefaultConnection' was not found in the applications configuration or the connection string is empty.” error.
3) Rebuild your project and then use a smilar definition like below in your razor view.
OR
1) Just add reference to System.Web.Helpers 2.0.0.0 dll which Basic template does not include by default.
2) After adding the reference, you need to open property for the dll and change Copy Local to True.

.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.

Unable to use Html.RenderParial if I reference System.Reactive.Core.dll in my project

I am trying to use RenderPartial since I have to reuse code from a different cshtml. So, I use:
#{ Html.RenderPartial("ViewMe"); }
But, I get this error instead :(.
Compiler Error Message:
EditMe.cshtml(1,4): 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\root\20f834d3\15233d01\assembly\dl3\a4d6f6b9\06975aaa_caebce01\System.Reactive.Core.DLL: (Location of symbol related to previous error)
Can someone help me with this please? I really don't understand how something so simple in Razor would not compile! I tried in the sample app and it is because of referencing System.Reactive.Core.dll. How do I fix this issue?
This is an issue with Reactive Libraries and MVC.
Add the following to <System.Web> section in Web.config:
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>

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.

upgrading from asp.net mvc 2.0 to 3.0 issues

after upgrade, all the pages see Models as Object.
I've upgraded using migration guide here
basically just copying some scripts, and re-mapping mvc assembly reference to 3.0
For some reason, all of my controls are now not seeing any properties on my models.
here is how i define the model type:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WebMVC.Models.WeatherModel>" %>
usage:
<%: Html.TextBox("DateFromText", Model.DateFrom.ToShortDateString())%>
i now get compile errors that "object" does not contain definition for AnyProperty.
UPDATE
thanks to SLax i fixed the object issue. Now getting the following error:
The type 'System.Data.Objects.DataClasses.ComplexObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
ok.. fixed this by adding assembly reference in web.config:
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
You will want to enter the following into the web.config file:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
You probably have references to System.Web.Mvc.dll version 2 in one of the two Web.config files.

Resources