Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 3개 있습니다.)
(시리즈 글이 4개 있습니다.)
닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
; https://www.sysnet.pe.kr/2/0/13458

닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법
; https://www.sysnet.pe.kr/2/0/13459

닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법
; https://www.sysnet.pe.kr/2/0/13460

닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법
; https://www.sysnet.pe.kr/2/0/13461




.NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법

예전에 작성한 COM 개체를,

C# COM 개체를 C++에서 사용하는 예제
; https://www.sysnet.pe.kr/2/0/12791

.NET Core 프로젝트로 마이그레이션한 다음 tlbexp 문제까지 해결하고 나서,

.NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
; https://www.sysnet.pe.kr/2/0/13458

마지막으로 regasm으로 등록하려고 했더니 ^^ 오류가 발생합니다.

c:\temp\cs_com_dll_cpp_sample\ClassLibrary1\bin\Debug> regasm /codebase ClassLibrary1.dll
Microsoft .NET Framework Assembly Registration Utility version 4.8.9032.0
for Microsoft .NET Framework version 4.8.9032.0
Copyright (C) Microsoft Corporation. All rights reserved.

RegAsm : error RA0000 : Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.


이번에도 System.Runtime이 나오는 걸로 봐서 tlbexp에서와 동일한 문제로 보이는데요, 예상과는 달리 .NET Core/5+ 버전의 regasm을 제공하는 방식으로 해결하지 않았습니다. 이에 대해서는 다음의 문서에서 잘 설명하고 있는데요,

Expose .NET Core components to COM
; https://learn.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com

의외로, 기존 C/C++ COM처럼 regsvr32.exe로 통합시켰습니다. 대신 기존의 regasm.exe가 하던 부가 작업을 수행하는 별도의 DLL을 생성하도록 바꿨는데요, 이를 위해 csproj 파일에 EnableComHosting 옵션을 추가해야 합니다.

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <!-- ...[생략]... -->
        <EnableComHosting>true</EnableComHosting>
    </PropertyGroup>
    <!-- ...[생략]... -->
</Project>

그럼 프로젝트 빌드 시 "ClassLibrary1.dll"과 함께 "ClassLibrary1.comhost.dll" 파일이 하나 더 생성됩니다. 그리고, regsvr32.exe로 등록 시에는 comhost DLL을 사용하면 됩니다.

C:\temp\cs_com_dll_cpp_sample\ClassLibrary1\bin\Debug> regsvr32 ClassLibrary1.comhost.dll

참고로 comhost DLL은 등록 시에만 사용되는 것은 아니고 이후 런타임에서도 사용되므로 삭제해서는 안 됩니다. 결국, .NET Framework에서는 1개의 DLL만 배포하면 되었는데, 이제는 2개의 DLL을 함께 배포해야 합니다.

(첨부 파일은 이 글의 예제 프로젝트를 포함합니다.)




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 11/26/2023]

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)
11035정성태8/29/201621664오류 유형: 354. .NET Reflector - PDB 생성 화면에서 "Clear Store"를 하면 "Index and length must refer to a location within the string" 예외 발생
11034정성태8/25/201625731개발 환경 구성: 296. .NET Core 프로젝트를 NuGet Gallery에 배포하는 방법 [2]
11033정성태8/24/201623595오류 유형: 353. coreclr 빌드 시 error C3249: illegal statement or sub-expression for 'constexpr' function
11032정성태8/23/201622809개발 환경 구성: 295. 최신의 Visual C++ 컴파일러 도구를 사용하는 방법 [1]
11031정성태8/23/201618914오류 유형: 352. Error encountered while pushing to the remote repository: Response status code does not indicate success: 403 (Forbidden).
11030정성태8/23/201622102VS.NET IDE: 111. Team Explorer - 추가한 Git Remote 저장소가 Branch에 보이지 않는 경우
11029정성태8/18/201629367.NET Framework: 602. Process.Start의 cmd.exe에서 stdin만 redirect 하는 방법 [1]파일 다운로드1
11028정성태8/15/201622364오류 유형: 351. Octave 설치 시 JRE 경로 문제
11027정성태8/15/201624076.NET Framework: 601. ElementHost 컨트롤의 메모리 누수 현상
11026정성태8/13/201625279Math: 19. 행렬 연산으로 본 해밍코드
11025정성태8/12/201624109개발 환경 구성: 294. .NET Core 프로젝트에서 "Copy to Output Directory" 처리 [1]
11024정성태8/12/201623324오류 유형: 350. "nProtect GameMon" 실행 중에는 Visual Studio 디버깅이 안됩니다! [1]
11023정성태8/10/201624886개발 환경 구성: 293. Azure 구독 후 PaaS 서비스 만들어 보기
11022정성태8/10/201625377개발 환경 구성: 292. Azure Cloud Service 배포시 사용자 정의 작업을 추가하는 방법
11021정성태8/10/201622234오류 유형: 349. System.Runtime.Remoting.RemotingException - Type '..., ..., Version=..., Culture=neutral, PublicKeyToken=null' is not registered for activation [2]
11020정성태8/10/201625277VC++: 98. 원본과 대상 버퍼가 같은 경우 memcpy, wmemcpy 주의점
11019정성태8/10/201642116기타: 60. 도서: 시작하세요! C# 6.0 프로그래밍: 기본 문법부터 실전 예제까지 (2쇄 정오표)
11018정성태8/9/201626286.NET Framework: 600. 단일 메서드 내에서의 할당으로 알아보는 자바와 닷넷의 GC 차이점 [1]
11017정성태8/9/201627634웹: 33. HTTP 쿠키에 한글 값을 설정하는 방법
11016정성태8/7/201625607개발 환경 구성: 291. Windows Server Containers 소개
11015정성태8/7/201623908오류 유형: 348. Windows Server 2016 TP5에서 Windows Containers의 docker run 실행 시 encountered an error during Start failed in Win32
11014정성태8/6/201624664오류 유형: 347. Hyper-V Virtual Machine Management service Account does not have permission to open attachment
11013정성태8/6/201635512개발 환경 구성: 290. Windows 10에서 경험해 보는 Windows Containers와 docker [4]
11012정성태8/6/201625561오류 유형: 346. Windows 10에서 Windows Containers의 docker run 실행 시 encountered an error during CreateContainer failed in Win32 발생
11011정성태8/6/201627088기타: 59. outlook.live.com 메일 서비스의 아웃룩 POP3 설정하는 방법
11010정성태8/6/201624065기타: 58. Outlook에 설정한 SMTP/POP3(예:천리안 메일) 계정 암호를 잊어버린 경우
... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...