在任何人将其作为重复项关闭之前 - 请注意它不是 linq 或其他数据源问题,并且我查看了其他 stackoverflow 帖子,没有一个是相同的。
这是我的问题:
它非常简单的应用程序 ASP.net,背后有 C# 代码,没有花哨的东西,简单得就像您从下面的代码中看到的那样:
default.aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%=returVar%>
默认.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
}
最后是 web.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.5。
那么为什么当我在桌面上运行此代码时会发生此错误,它就像通过 firefox 使用 http 的魅力一样,如下所示:
http://localhost:3117/Default.aspx?test=0998989765432345
完全相同的代码失败并附带屏幕截图,有人可以告诉我为什么请提出解决方案。我尝试将解决方案资源管理器中的所有 DLL 包含到要发布的版本中,即解决方案资源管理器 > 引用 > system.core、system.data 等... > 全部设置为 copy local = true。
还是没有运气。
请注意,我无法在服务器上安装任何额外的组件,并且我必须部署的内容必须是应用程序的一部分。
最佳答案
如果其他人遇到这种情况,最简单的解决方案是我如何实现结果
加载后打开 Visual studio 2010
打开资源管理器 -> 转到 > C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0
将所需的 System.ComponentModel.DataAnnotations.dll 复制到项目“References”文件夹中,选择该引用,并在属性下将“copy local”设置为 true,一旦发布,它将位于您的 bin 文件夹中,并且完全不会影响任何服务器,无论是 x32 还是 x64。
希望它对其他人有帮助。
关于asp.net - 类型或命名空间名称 'DataAnnotations' 在命名空间 'System.ComponentModel' 中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9164717/