네임 스페이스가 인식되지 않습니다 (있는 경우에도)
이 오류가 발생합니다.
유형 또는 네임 스페이스 이름 'AutoMapper'를 찾을 수 없습니다 (사용 지시문 또는 어셈블리 참조가 누락 되었습니까?)
재미있는 점은 이미 프로젝트에 해당 참조가 있다는 것입니다.
그리고 이것은 내 코드입니다.
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 파일을 참조하는 두 개의 다른 프로젝트가 있다는 것입니다. 둘 다 완벽하게 작동합니다.
다음은 하나의 스크린 샷입니다.
그리고 여기에 코드가 잘 컴파일되어 있습니다.
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>();
}
속성 페이지에서 두 참조가 동일한 데이터를 가지고있는 것 같습니다.
내가 무엇을 놓치고 있습니까?
나는 시도했다 :
- Visual Studio 다시 시작
- (즉, using 문없이 참조
AutoMapper.Mapper.CreateMap
) - 청소 및 재건
다른 아이디어가 있습니까?
프로젝트가 .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.
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.
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.
Let me ask a stupid question: Could there be two automapper.dll files? One with an AutoMapper
namespace and one without? Confirm the paths in both projects.
I also noticed that the order of the using
commands is different. It shouldn't matter, but have you tried to shuffle them?
If your class does not compile, even if it is in the project check these:
- whether class name is exactly the same
- whether name space is exactly the same
- whether class properties show build action = compile
I resolved this issue by right clicking on the folder containing the files and choosing Exclude From Project and then right clicking again and selecting Include In Project (you first have to enable Show All Files to make the excluded folder visible)
I have a similar problem with references not being recognized in VS2010 and the answers herein were not able to correct it.
The problem in my solution was related to the extension of the path where the project referenced was located. As I am working with SVN, I made a branch of a repository to do some testing and that branch increased two levels in path structure, so the path became too long to be usable in windows. This did not throw any error but did not recognize the namespace of the project reference. When I correct the location of the project to have a smaller path everything went fine.
This has to be the simplest solution if all the other answers does not help you
I was searching for what's wrong with my setup among the answers, Tried all of them - none worked, Then I realized Visual Studio 2018 was developed by Microsoft. So I did what most people do,
Restarted Visual Studio And It worked
In my case, the referenced dll was build in higher version of .Net Framework. After I added the reference, I could use it. But as soon as I did a build, the 'missing reference' error will pop up. I refresh the dll the error will go but it would never build. This post made me check the framework version and thus I could resolve it by building the referenced project in same version.
Perhaps the project's type table is in an incorrect state. I would try to remove/add the reference and if that didn't work, create another project, import my code, and see if that works.
I ran into this while using VS 2005, one would expect MS to have fixed that particular problem by now though..
The question has already been awarded, but there are additional details not yet described that need to be checked.
I too was having this behavior, where project B was referenced in project A, but the namespace of project B was not recognized in project A. After some digging, I found my path was too long. By reducing the path of the projects (both A and B) the references became visible and available.
I tested this theory by creating project C at a much lesser path depth. I referenced project C in project A. The references worked correctly as expected. I then removed project C from the solution, merely moved project C to a deep path, the same as project B, and added project C back to the solution, and tried to compile. I then had no visibility to project C objects any longer.
In my case i had copied a classlibrary, and not changed the "Assembly Name" in the project properties, so one DLL was overwriting the other...
I faced similar problem of namespace/method not being found during execution although it was fine during compilation, and the reason for this appears to be that the assembly I was referencing was deployed to GAC and since then was changed, so when I referenced the assembly in Visual Studion it was using the most recent one, but during runtime the version fro GAC had been used.
In my case I got the error only in VS 2015. When opening the project in VS 2017 the error was gone.
Crazy. I know.
Tried all options here. Restarting, cleaning, manually checking in generated DLLs (this is invaluable to understanding if it's actually yourself that messed up).
I got it to work by setting the Verbosity of MSBuild to "Detailed" in Options.
This question has already been answered for the original poster, but in case someone encounters this in an MS-Test project:
from within Visual Studio, click the Test menu -> Test Settings -> Default Processor Architecture and ensure that the architecture matches that of the other assembly that you're referencing. If the other assembly is x64 and your test settings are x86, you may experience the symptoms that the original poster had.
I was working on Xamarin project and as always, deleting obj folder and rebuilding solved my issue, the namespace my VS was not recognizing was a code in my own project BTW
In my case removing/adding that assembly worked.
참고 URL : https://stackoverflow.com/questions/4228992/namespace-not-recognized-even-though-it-is-the-there
'Programing' 카테고리의 다른 글
로딩 / 진행 표시기를 표시하는 가장 좋은 방법은 무엇입니까? (0) | 2020.06.21 |
---|---|
"경고 CS4014 :이 호출을 기다리지 않기 때문에 현재 메소드의 실행이 계속됩니다 ..."억제 (0) | 2020.06.21 |
GIT에서 부분 복귀를 할 수 있습니까 (0) | 2020.06.21 |
어떤 깊이에서든 이름으로 요소에 대한 XDocument 쿼리 (0) | 2020.06.21 |
사이트 코더 바이트에서 'gets (stdin)'은 어떻게됩니까? (0) | 2020.06.21 |