'Error using C++/CLI dll in Azure function (zip deployed)

So I have:

  1. a c++/cli wrapper withini a clr c++ dll
  2. a c# net6 azure function which is referencing the c++/cli project

The issue:

  • It works perfectly when I'm testing it in local (with visual studio)

  • When it's published (zip) on Azure I can call functions that don't use the c++/cli dll, but when I'm calling (via Test/Run button) a function that use my c++/cli lib I have this error code 500 Internal Server Error and this error message:

    Could not load file or assembly 'C:\home\site\wwwroot\bin\MyCliDll.dll'. Format of the executable (.exe) or library (.dll) is invalid.

I have try a lot of different publishing configuration but non of them worked.

at this point I don't have any idea of what to change i order to make it works, is it a compatibility problem between my c++ and Azure ?

In case, here both of my setup:

<!--Publishing Setup-->
<Project>
  <PropertyGroup>
    <UserName>XXXXX</UserName>
    <WebPublishMethod>ZipDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>x64</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>XXXXXX</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>false</LaunchSiteAfterPublish>
    <ResourceId>XXXXXXXX</ResourceId>
    <_SavePWD>true</_SavePWD>
    <PublishUrl>XXXXXXXX</PublishUrl>
    <TargetFramework>net6.0</TargetFramework>
    <SelfContained>false</SelfContained>
    <SkipExtraFilesOnServer>true</SkipExtraFilesOnServer>
  </PropertyGroup>
</Project>
<!--csproj-->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
      <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Library</OutputType>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
      <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
      <ProjectReference Include="..\..\MyCliDllProject\build\MyCliDll.vcxproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>


Solution 1:[1]

Ok I feel a bit dumb I just needed to go to the portal Azure in Configuration->General Settings->Platform and set it to 64 bit...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DavEat