4

I have used a dll to my project which gets added to my project file as a COMReference like following

<COMReference Include="GENERALCREDITREQUESTMANAGER450Lib">
  <Guid>{BDB6DDB5-5C02-492F-954E-68ED3D8F075D}</Guid>
  <VersionMajor>1</VersionMajor>
  <VersionMinor>0</VersionMinor>
  <Lcid>0</Lcid>
  <WrapperTool>tlbimp</WrapperTool>
  <Isolated>False</Isolated>
  <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>

Now the problem is it fails during my pipeline build, saying Namespace or type GENERALCREDITREQUESTMANAGER450Lib can't be found which is understandable because unlike other references it doesn't have any HintPath to locate the dll.

After looking around a bit I found this article that basically says use tlbImp to generate the dll and then reference that dll using the following syntax:

<Reference Include="GENERALCREDITREQUESTMANAGER450Lib">
  <HintPath>InteropAssemblies\GENERALCREDITREQUESTMANAGER450Lib.dll</HintPath>
  <EmbedInteropTypes>true</EmbedInteropTypes>
</Reference>

But if I do that then my visual studio build fails, because then VS can't find the namespace even though it's added to the reference. One of the post suggested to use COMFileReference instead of COMReference but that ends up with same "Namespace not found" error.

How can I make the pipleline working?

SZT
  • 1,771
  • 4
  • 26
  • 53
  • 1
    when you used `tlbImp` manually, did you use its `/namspace:GENERALCREDITREQUESTMANAGER450Lib` option? - [Reference](https://learn.microsoft.com/en-us/dotnet/framework/tools/tlbimp-exe-type-library-importer) – Martin Ullrich Apr 13 '21 at 09:56
  • @MartinUllrich: That was it! Thanks a lot! If you post that as answer I will accept that as answer. – SZT Apr 13 '21 at 13:29

1 Answers1

2

The COMReference item requires the library to registered on the build server which may be hard to do depending on the environment.

The way to use tlbimp locally and add the generated .dll to the project sources is likely more compatible for your setup though it requires you to pass the namespace as a parameter (/namspace:GENERALCREDITREQUESTMANAGER450Lib) to achieve the same result as the COMReference.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217