how to upgrade code to a new version of third party control - asp.net

I have a web application in asp.net 3.5 where i have been using some third party controls i.e. Devexpresv9.2
and on the pages where i am using these controls i normally has to call the register tag on the page markup like for ex:
<%# Register Assembly="DevExpress.Web.v9.2, Version=9.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%# Register Assembly="DevExpress.Web.ASPxGridView.v9.2.Export, Version=9.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
Now i have updated the version of devexpress controls installed on my machine and it has stopped working because the version installed on my machine is v10.0 but my code is looking for v9.2
Please advise how can i modify my code in such a way that in future if i install another version then i don't have to modify all the pages and references again. May be something in web.config that can help me or anything generic??
Thanks

Use the project converter which is designed for this. It is located under the Windows Start Menu at "Develper Express V2010 vol1 -> Components -> Tools -> Project Converter". This will automatically change all of your references to the current version.
Project Converter Documentation

I think you answered your own question. You don't need to add the assembly reference on each page, put it in web.config.
<system.web>
<compilation>
<assemblies>
<add assembly="DevExpress.Web.v9.2, Version=9.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a">
<add assembly="DevExpress.Web.ASPxGridView.v9.2.Export, Version=9.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a">
</assemblies>
</compilation>
<pages>
<controls>
<add namespace="DevExpress.Web.ASPxCallback" assembly="DevExpress.Web.v9.2" tagprefix="dxcb">
<add namespace="DevExpress.Web.ASPxGridView.Export" assembly="DevExpress.Web.ASPxGridView.v9.2.Export" tagprefix="dxwgv">
</controls>
</pages>
</system.web>

Related

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

Web.Config Assembly/Reference Issue

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.

How to register tagPrefix in app.config

in my ASP.net project's web.config I register the tagprefix cr as follows:
<pages>
<controls>
<add tagPrefix="cr" namespace="CrystalDecisions.Web" assembly="CrystalDecisions.Web,Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</controls>
</pages>
I would like to start using configuration specific app.configs, but if I include the same setting in the app.config I get an error at compile time saying that the tagprefix is unrecognized
How can I force recognition of the tagprefix when it is in app.config instead of web.config
app.config is not used in a web project; anything you put in that file might as well not exist; ASP.NET and IIS completely ignore that file.

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