类型或命名空间名称“DataAnnotations”不存在于命名空间“System.ComponentModel” [英] The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel'

查看:502
本文介绍了类型或命名空间名称“DataAnnotations”不存在于命名空间“System.ComponentModel”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何人关闭此作为重复之前 - 请注意它不是一个linq或其他数据源问题,我已经看过其他stackoverflow文章,没有相同。



这里是我的问题:





它非常简单的应用程序ASP.net与C#代码背后没有花哨的东西简单,你可以从下面的代码看到:



default.aspx代码

 <%@ Page Language =C#AutoEventWireup =trueCodeFile =Default.aspx .csInherits =_ Default%> 

<%= returVar%>

Default.apsx.cs

 使用系统; 
使用System.Collections.Generic;
使用System.Web;
使用System.Web.UI;
使用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]);
//下面我们将把数据库连接解析后的代码放在ODP.net
if(n.Length == 16)
{
returVar =Found;
}
else
{
returVar =未找到;
}
} // Page_Load
}

.config

 <?xml version =1.0?> 
< configuration>
< system.web>
< compilation debug =false/>
< /system.web>
< / configuration>

我的开机是:win 32 xp visual studio 2010和服务器运行是Win 64bit 2008 R2和IIS7所以为什么当我在桌面上运行这个代码时出现这个错误,这个错误就像一个通过firefox的http通过如下方式发挥的魅力:



http:// localhost:3117 / Default.aspx?test = 0998989765432345



完全相同的代码失败,附带的屏幕截图,有人可以告诉我为什么请提出解决方案。我尝试从解决方案资源管理器中包含我的所有DLL,即解决方案资源管理器>参考资料> system.core,system.data等...全部设置为copy local = true。



仍然没有运气。



请注意,我无法在服务器上安装任何额外的组件,我必须部署什么才能成为应用程序的一部分。 >

解决方案

如果有人碰到这种情况,最简单的解决方案,这是我如何实现结果



打开Visual studio 2010一旦加载



打开资源管理器 - > goto> C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\\ \\ v4.0



将所需的System.ComponentModel.DataAnnotations.dll复制到项目参考文件夹中,选择该引用,并在属性下将copy local设置为true,一旦你发布它将在你的bin文件夹,并不影响任何服务器,无论是x32还是x64。



希望它有助于任何人。


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:

Its extremely simple app ASP.net 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" %>

<%=returVar%>

Default.apsx.cs

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 ODP.net once the DB connectivity is resolved
        if (n.Length == 16)
        {
            returVar = "Found";
        }
        else
        {
            returVar = "Not found";
        }
    }//Page_Load
}

and finally web.config

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="false"/>
    </system.web>
</configuration>

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:

http://localhost:3117/Default.aspx?test=0998989765432345

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, system.data 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.

解决方案

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.

这篇关于类型或命名空间名称“DataAnnotations”不存在于命名空间“System.ComponentModel”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆