The type or namespace name ‘DataAnnotations’ does not exist in the namespace ‘System.ComponentModel’


Before anyone closes this as duplicate – please note its not a linq or other datasources issue and i have looked at other stackoverflow posts and none are same.

Here is my problem:

Error Screen Shot

Its extremely simple app with C# code behind no fancy stuff plain simple as you can see from code below:

default.aspx code

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>



using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    public string returVar;
    protected void Page_Load(object sender, EventArgs e)
        string n = String.Format("{0}", Request.Form["test"]);
        //below we will place the code for once the DB connectivity is resolved
        if (n.Length == 16)
            returVar = "Found";
            returVar = "Not found";

and finally web.config

<?xml version="1.0"?>
        <compilation debug="false"/>

My dev machine is: win 32 xp visual studio 2010 and Server running is Win 64bit 2008 R2 and IIS7.5.

so why is this error occuring when i run this code on my desktop it works like a charm with http through firefox as below:


exact same code fails with attached screen shot, can someone tell me why please propose the solution. I tried including ALL of my DLL from solution explorer to release i.e. Solution Explorer > References > system.core, etc… > all set for copy local = true.

still no luck.

Please note i cant install any extra components on the server and what ever i have to deploy has to be part of application.

Best Solution

Easiest solution if anyone else bumps into this situation, here is how i achieved result

open Visual studio 2010 once its loaded

open explorer -> goto > C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0

copy the required System.ComponentModel.DataAnnotations.dll into your project "References" folder select that reference and under properties set "copy local" to true and once you publish it will be in your bin folder and wont impact at all on any server be it x32 or x64.

hope it helps anyone else.

Related Question