upgrading from asp.net mvc 2.0 to 3.0 issues - asp.net

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.

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)?

System.Net.Http missing?

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" />

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>

After converting MVC 2 to MVC 3 I am getting the: Could not load type 'System.Web.Mvc.ViewTypeParserFilter'

I used Mvc3AppConverter and converted MVC2 to MVC3 and after getting the compilation error of Tag-builder I added the System.Web.WebPages reference, but now I am getting the following web config error :
Parser Error Message: Could not load type 'System.Web.Mvc.ViewTypeParserFilter'.
Source Error:
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter" pageBaseType="System.Web.Mvc.ViewPage" userControlBaseType="System.Web.Mvc.ViewUserControl">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.Mvc" tagPrefix="mvc" />
Does your app's root web.config file have an assembly binding redirect for System.Web.Mvc from versions 1.0-2.0 to 3.0?
Also, try using the assembly-qualified type name: "System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

Import Namespace System.Query

I am trying to load Linq on my .Net 3.5 enabled web server by adding the following to my .aspx page:
<%# Import Namespace="System.Query" %>
However, this fails and tells me it cannot find the namespace.
The type or namespace name 'Query' does not exist in the namespace 'System'
I have also tried with no luck:
System.Data.Linq
System.Linq
System.Xml.Linq
I believe that .Net 3.5 is working because var hello = "Hello World" seems to work.
Can anyone help please?
PS: I just want to clarify that I don't use Visual Studio, I simply have a Text Editor and write my code directly into .aspx files.
I have version 2 selected in IIS and I
Well, surely that's your problem? Select 3.5.
Actually, here's the real info:
http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx
What does the part of your web.config file look like?
Here's what it looks like for a brand new ASP.NET 3.5 project made with Visual Studio 2008:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, 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"/>
</assemblies>
I found the answer :) I needed to add the following to my web.config:
<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"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
Then I could add the following to my code:
<%# Import Namespace="System.Linq" %>
#Will,
Thanks for your help. I have accepted one of your answers :)
Make sure your project is set to target 3.5, and not 2.0.
As others have said, your 'var' test is a test of C#3 (i.e. VS2008), not the 3.5 framework.
If you set the project framework target settings properly, you should not expect to need to manually add dll references at this point.
The var hello stuff is compiler magic and will work without Linq.
Try adding a reference to System.Core
Sorry, I wasn't clear. I meant add System.Core to the web project's references, not to the page.
The Import on the page are basically just using statements, allowing you to skip the namespace on the page.
The csproj file might be missing the System.Core reference.
Look for a line in the csproj file like this:
<Reference Include="System" />
And add a line below it like this:
<Reference Include="System.Core" />

Resources