命名空间不承认(即使它是存在的) [英] Namespace not recognized (even though it is there)

查看:483
本文介绍了命名空间不承认(即使它是存在的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误:

类型或命名空间名称'AutoMapper'找不到(是否缺少using指令或程序集引用?)

The type or namespace name 'AutoMapper' could not be found (are you missing a using directive or an assembly reference?)

有趣的是,我已经在我的项目的参考:

The funny thing is that I have that reference in my project already:

这是我的code:

using System.Collections.Generic;
using DataContract;
using SelectorDAL;
using AutoMapper;

namespace SpecimenSelect
{
    public class SpecimenSelect : ISpecimenSelect
    {
        public SpecimenSelect()
        {
            SetupMaps();
        }

        private static void SetupMaps()
        {
            Mapper.CreateMap<SpecimenDetail, SpecimenDetailContract>();
        }

另外奇怪的是,我在我的解决方案,另外两个项目,这两个使用AutoMapper和引用的是完全相同的AutoMapper.dll文件。他们都完全正常工作。

The other weird thing is that I have two other projects in my solution that both use AutoMapper and are referencing the exact same AutoMapper.dll file. They both work perfectly fine.

下面是一个屏幕截图:

和这里是code(即编译罚款):

and here is that code (that compiles fine):

using System.Collections.Generic;
using AutoMapper;
using DataContract;
using SelectorDAL;

namespace PatientSelect
{

    public class PatientSelect : IPatientSelect
    {
        public PatientSelect()
        {
            SetupMaps();
        }

        private void SetupMaps()
        {
            Mapper.CreateMap<Patient, PatientContract>();
            Mapper.CreateMap<OrderedTest, OrderedTestsContract>();
            Mapper.CreateMap<Gender, GenderContract>();
        }

引用都似乎有属性页上相同的数据。

Both references seem to have the same data on the properties page.

我是什么失踪?

我试过:


  1. 重新启动Visual Studio中

  2. 引用不using语句(即 AutoMapper.Mapper.CreateMap

  3. 清理和重建

任何其他的想法?

推荐答案

检查以确保您的项目没有被设置为使用.NET Framework 4的客户端配置文件。

Check to make sure that your project isn't set up to use the .NET Framework 4 Client Profile.

您可以检查/改变这种右键单击您的项目(不解决方案),选择属性 - > 应用 - > 目标框架。目标框架是页面上的下拉列表。

You can check/change this by right-clicking your project (not the solution), select Properties -> Application -> Target framework. The target framework is a dropdown on that page.

这是在Visual Studio(我甚至会走这么远,称之为一个bug)的问题。 AutoMapper需要被排除在.NET Framework 4客户端配置文件集。因为你的项目使用的版本,它打破了框架。

This is a problem in Visual Studio (I would even go so far as to call it a bug). AutoMapper requires assemblies that are excluded from the .NET Framework 4 Client Profile. Since your project is using that version of the framework it breaks.

在.NET Framework版本为你引用的项目比这个项目使得较高的参考类似的错误将传播到整个构建过程。即一个项目目标4.5引用了项目目标4.5.1会给你此相同的错误。

A similar error will propagate to the build process when the .NET Framework version for the project you are referencing is higher than the project making the reference. i.e. A project targeting 4.5 that references a project targeting 4.5.1 will give you this same error.

需要有一个更好的错误消息,当出现这种情况是因为没有合理的解释,为什么作为错误消息告诉您引用您已经清楚地引用的程序将无法建立。

There needs to be a better error message when this happens because there is no rational explanation as to why it would not build as the error message tells you to reference an assembly you have clearly referenced.

这篇关于命名空间不承认(即使它是存在的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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