Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Windows 10에서 Fake 어셈블리를 생성하는 경우 빌드 시 The type or namespace name '...' does not exist in the namespace 컴파일 오류 발생

Visual Studio 2015의 경우, .NET 3.5 프로젝트에 대해 단위 테스트를 생성하면 기본적으로 .NET 4.6 대상의 테스트 프로젝트가 생성됩니다. 그런데, 그렇게 지정된 테스트 프로젝트의 System.dll에 대한 Fake 어셈블리를 생성하는 경우 빌드 시 다음과 같은 오류가 발생할 수 있습니다. (System.dll에 대해 Fake를 생성하면 그것이 참조하고 있는 mscorlib.dll에 대해서도 Fake 어셈블리가 생성됩니다.)

Severity    Code    Description Project File    Line    Suppression State
Error   CS0234  The type or namespace name 'EventSourceCreatedEventArgs' does not exist in the namespace 'System.Diagnostics.Tracing' (are you missing an assembly reference?) [C:\ConsoleApplication1Tests\obj\Debug\Fakes\m\f.csproj] ConsoleApplication1Tests    C:\ConsoleApplication1Tests\f.cs    18545   Active

Severity    Code    Description Project File    Line    Suppression State
Error   CS0115  'StubDSA.VerifyData(Stream, byte[], HashAlgorithmName)': no suitable method found to override [C:\ConsoleApplication1Tests\obj\Debug\Fakes\m\f.csproj]  ConsoleApplication1Tests    C:\ConsoleApplication1Tests\f.cs    177476  Active

왜냐하면, EventSourceCreatedEventArgs 타입과 DSA.VerifyData 메서드는 모두,

EventSourceCreatedEventArgs Class
; https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.tracing.eventsourcecreatedeventargs

DSA.VerifyData Method (Byte[],?Byte[],?HashAlgorithmName)
; https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.dsa.verifydata

.NET 4.6.2부터 제공되는 것으로 .NET 4.6에는 없기 때문입니다. 결과적으로 보면 이건 Visual Studio의 버그로 보입니다. .NET 4.6 프로젝트가 참조하고 있는 mscorlib.dll에 대해 Fake 어셈블리를 생성할 때 기본적으로 .NET 4.6.2 버전의 mscorlib.dll을 기준으로 Fake 어셈블리를 생성하는 것이기 때문입니다.

즉, 이 현상은 .NET 4.6.2가 설치된 컴퓨터에 한해서 발생합니다.

해결 방법은, 문제가 되는 대상 타입들을 Fake 어셈블리에서 제외하도록 하는 것입니다. 예전에도 이에 대한 제어 방법을 한 번 설명했었는데요. ^^

Visual Studio 빌드 오류 - error CS0122: '__ComObject' is inaccessible due to its protection level
; https://www.sysnet.pe.kr/2/0/11039

따라서, "mscorlib.fakes" 파일에 다음과 같이 Remove 태그를 추가해 주면 됩니다.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
    <Assembly Name="mscorlib" Version="4.0.0.0"/>

    <StubGeneration>
        <Remove TypeName="EventSourceCreatedEventArgs"/>
        <Remove FullName="System.Security.Cryptography.DSA"/>
        <Remove FullName="System.Diagnostics.Tracing.EventListener"/>
    </StubGeneration>
</Fakes>

(TypeName은 클래스 이름만 지정해 주면 되는 반면, FullName은 Namespace까지 모두 포함해 지정해야 합니다.)




참고로, 설치된 닷넷 프레임워크의 버전을 확인하는 방법은 다음의 글에 자세히 나와 있습니다.

How to: Determine Which .NET Framework Versions Are Installed
; https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed

Windows 10의 경우, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" 경로에서 "Release" 값이 "394802"로 되어 있을 텐데 이는 .NET 4.6.2가 설치되었다는 의미입니다. (Windows 10 Anniversary 업데이트 이후 설치됩니다.) 다른 운영체제의 경우, 다음의 경로에서 4.6.2를 다운로드 할 수 있습니다.

Microsoft .NET Framework 4.6.2 (Offline Installer) for Windows 7 SP1, Windows 8.1, Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2 
; https://www.microsoft.com/en-us/download/details.aspx?id=53344

이렇게 설치된 경우 Release 값은 "394806"입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [106]  107  108  109  110  111  112  113  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
10980정성태5/24/201614366VS.NET IDE: 108. Visual Studio 2013/2015를 위한 "Macros for Visual Studio"
10979정성태5/23/201617932.NET Framework: 591. C# - 조합(Combination) 예제 코드 - 두 번째 이야기파일 다운로드1
10978정성태5/23/201616828.NET Framework: 590. C# - 모든 경우의 수를 조합하는 코드 (2)파일 다운로드1
10977정성태5/23/201621274.NET Framework: 589. C# - 모든 경우의 수를 조합하는 코드 (1)파일 다운로드1
10976정성태5/20/201615098Math: 18. C# - 오일러 공식을 이용한 복소수 값의 라디안 회전파일 다운로드1
10975정성태5/20/201615441Math: 17. C# - 복소수 타입의 승수를 지원하는 Power 메서드파일 다운로드1
10974정성태5/20/201616421.NET Framework: 588. C# - OxyPlot 라이브러리로 복소수 표현파일 다운로드1
10973정성태5/20/201621140.NET Framework: 587. C# Plotting 라이브러리 OxyPlot [3]파일 다운로드1
10972정성태5/19/201620201Math: 16. C# - 갈루아 필드 GF(2) 연산 [3]파일 다운로드1
10971정성태5/19/201614264오류 유형: 334. Visual Studio - 빌드 시 경고 warning MSB3884: Could not find rule set file "...". [2]
10970정성태5/19/201617541오류 유형: 333. OxyPlot 라이브러리의 컨트롤을 Toolbox에 등록 시 오류 [2]
10969정성태5/18/201617666.NET Framework: 586. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (3) - "Open with" 목록에 등록파일 다운로드1
10968정성태5/18/201612238오류 유형: 332. Visual Studio - 단위 테스트 생성 시 "Design time expression evaluation" 오류 메시지
10967정성태5/12/201616784.NET Framework: 585. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (2) - 웹 브라우저가 다운로드 후 자동 실행
10966정성태5/12/201623654.NET Framework: 584. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (1) - 기본 [1]파일 다운로드1
10965정성태5/12/201616695디버깅 기술: 81. try/catch로 조용히 사라진 예외를 파악하고 싶다면?
10964정성태5/12/201615369오류 유형: 331. ASP.NET에서 System.BadImageFormatException 예외가 발생하는 경우
10963정성태5/11/201616336VS.NET IDE: 107. Visual Studio 2015의 "DTAR_..." 특수 폴더가 생성되는 문제파일 다운로드2
10962정성태5/11/201618108오류 유형: 330. Visual Studio 단위 테스트 시 DisconnectedContext 예외 발생
10961정성태5/11/201617397.NET Framework: 583. 문제 재현 - Managed Debugging Assistant 'DisconnectedContext' has detected a problem in '...'파일 다운로드1
10960정성태5/10/201614994오류 유형: 329. ATL 메서드 추가 마법사 창에서 8ce0000b 오류 발생
10959정성태5/9/201617248.NET Framework: 582. CLR Profiler - 별도 정의한 .NET 코드를 호출하도록 IL 코드 변경파일 다운로드1
10958정성태5/6/201639982개발 환경 구성: 284. "Let's Encrypt"에서 제공하는 무료 SSL 인증서를 IIS에 적용하는 방법 (1) [3]
10957정성태5/3/201618895오류 유형: 328. 윈도우 백업 시 오류 - 0x80780166 두 번째 이야기 [1]
10956정성태5/3/201615089Windows: 117. BitLocker - This device can't use a Trusted Platform Module.
10955정성태5/3/201620811.NET Framework: 581. C# - 순열(Permutation) 예제 코드파일 다운로드2
... [106]  107  108  109  110  111  112  113  114  115  116  117  118  119  120  ...