6

I am creating plugins for a software called BIM Vision. They have a wrapper around a C API and thus I am using UnmanagedExports to have my unmanaged DLL compiled fine with the wrapper.

Issue is that I cannot use NuGet librairies at all in my project. They compile fine but calling any of their functions in my code crashes the software.

All the libraries are compiled in their own separate DLLs alongside my own DLL. Only my DLL can be loaded by the software (because the other DLLs miss code to talk to BIMVision)

How can I make the software find the missing DLLs ? Where should I place them?

My .csproj looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{362E40F4-4A37-48B3-A7A5-93E5535A9B22}</ProjectGuid>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>ExcelLink</RootNamespace>
        <AssemblyName>ExcelLink</AssemblyName>
        <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\bim_vision_exe\plugins</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>x86</PlatformTarget>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>..\..\..\bim_vision_exe\plugins\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>x86</PlatformTarget>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="PresentationCore" />
        <Reference Include="System" />
        <Reference Include="System.configuration" />
        <Reference Include="System.Core" />
        <Reference Include="System.Drawing" />
        <Reference Include="System.Security" />
        <Reference Include="System.Xml.Linq" />
        <Reference Include="System.Data.DataSetExtensions" />
        <Reference Include="Microsoft.CSharp" />
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
    </ItemGroup>
    <ItemGroup>
        <Compile Include="C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\sdk .NET\BIMVision.cs">
            <Link>BIMVision.cs</Link>
        </Compile>
        <Compile Include="ExcelLink.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="EPPlus" Version="4.5.3.3" />
        <PackageReference Include="UnmanagedExports" Version="1.2.7" />
        <PackageReference Include="ZetaIpc" Version="1.0.0.9" />
    </ItemGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    <Import Project="C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\exmaples .NET\vs_2013\packages\UnmanagedExports.1.2.7\tools/RGiesecke.DllExport.targets" Condition="Exists('C:\Users\Daniel\Documents\SAMT\BIMVISION SDK\exmaples .NET\vs_2013\packages\UnmanagedExports.1.2.7\tools/RGiesecke.DllExport.targets')" />
</Project>

Managed to use the debugger to get the real exception out of the software:

Exception thrown at 0x75AA9962 in bim_vision.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0019C458.
defvs Daniel
  • 300
  • 3
  • 15
  • 1
    Does this answer your question? [How can I make my managed NuGet package support C++/CLI projects?](https://stackoverflow.com/questions/18694947/how-can-i-make-my-managed-nuget-package-support-c-cli-projects) – JonasH Aug 18 '20 at 09:07
  • Doesnt seem to be related to my issue. I am using only C# code; the issue is that nuget packages are not compiled with my DLL and trying to run code from any nuget package crashes as it cannot find the code – defvs Daniel Aug 18 '20 at 09:25
  • 1
    @cab13140 what your comment says is completely different to what your question says. Which is correct? Edit the question if necessary. – Ian Kemp Aug 18 '20 at 10:32
  • Both say the same thing. Comment says they are not compiled under the same DLL which is correct and question says they are compiled alongside aka one DLL per dependency – defvs Daniel Aug 18 '20 at 12:16
  • 3
    That unmanaged app probably looks in the plugins folder for a DLL to load. But that is not where the CLR looks for dependent assemblies. It looks in the GAC, next in the directory where the .exe is stored, next raises the AppDomain.AssemblyResolve event. Three ways to keep it happy. One more is to write a somename.exe.config file with the probing element. – Hans Passant Aug 18 '20 at 15:04
  • I tried to install the DLLs in the GAC (using gacutil) but no luck with that yet. Same with putting library DLLs in same folder. – defvs Daniel Aug 19 '20 at 14:03
  • @HansPassant see my edit. Nothing seems to work. I also tried ILMerge but it wouldn't work since my main DLL is unmanaged – defvs Daniel Aug 19 '20 at 15:11
  • 1
    @HansPassant you were correct. Installed the correct version in the GAC and now it works fine. Feel free to post answer for the bounty... – defvs Daniel Aug 21 '20 at 06:37
  • 1
    Try to put the line with a C# code in a try/catch block. In the catch, log the exception somewhere so you can see more details about the .NET error that occurs since the C++ application probably swallows your .NET exception and throws the one you mentioned. – Sherif Elmetainy Aug 24 '20 at 01:00
  • Using the GAC to manage an SDK? Sounds like a hassle to me. – defines Aug 24 '20 at 23:40

1 Answers1

2

Installing the library DLLs in the GAC, using GACUTIL as follows, fixes the issue.

gacutil /i [path.dll]

It still wasn't running because of version mismatch for System.Buffers package; I installed the correct version and it worked.

defvs Daniel
  • 300
  • 3
  • 15