Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NuGet libraries in an Unmanaged C# .NET library project

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.
like image 913
defvs Daniel Avatar asked Aug 18 '20 08:08

defvs Daniel


Video Answer


1 Answers

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.

like image 121
defvs Daniel Avatar answered Oct 12 '22 23:10

defvs Daniel