What's new

Visual Studio 2022 Connecting to API Errors

KageDev

Member
Hello,

I am trying to connect to the Alibre API using the Getting Started tab as reference. I have tried running the program a couple different ways but both come up with errors. I've tried building and starting the program through Visual Studio and come up with this error:
System.BadImageFormatException
HResult=0x8007000B
Message=Could not load file or assembly 'AlibreX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

I've also tried using dotnet run to start the program but come up with this error:
C:\Program Files\dotnet\sdk\6.0.417\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "AlibreX", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align
the processor architectures between your project and references, or take a dependency on references with a processor architecture the processor architectures between your project and references, or take a dependency
that matches the targeted processor architecture of your project.

I've tried looking through the forums and couldn't find a post with a solution.
 

simonb65

Alibre Super User
Your application needs to be built with the same version of .NET that the API (AlibreX.dll) is built against. That is currently .NET 4.8 and your project architecture needs to be built as x64.

This is my project settings for a Alibre v26 Add-On in VS2019 ...

1700249080189.png

1700249103138.png
 

KageDev

Member
I see, I think that explains why dotnet run doesn't work. In my Project Properties, I do have the Target Framework set to .NET 4.8 and build for x64. Could it be the Public Key Token being Null that could cause the issue? I'm not sure what my App.config and packages.config should look like.
 

stepalibre

Alibre Super User
I see, I think that explains why dotnet run doesn't work. In my Project Properties, I do have the Target Framework set to .NET 4.8 and build for x64. Could it be the Public Key Token being Null that could cause the issue? I'm not sure what my App.config and packages.config should look like.
You need to make sure to pick the .NET Framework project templates and not .NET core/standard. Look for (.NET Framework).

OR you can change the target framework to <TargetFramework>net48</TargetFramework> in SDK projects.

C:\Program Files\dotnet\sdk\6.0.417\
This is .NET 6.

Here is a working SDK project setup for .NET 4.8 / 4.8.1

Code:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net481</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="AlibreX">
      <HintPath>..\..\..\..\Program Files\Alibre Design 27.0.0.27038\Program\AlibreX.dll</HintPath>
      <Private>True</Private>
    </Reference>
  </ItemGroup>
</Project>
 
Last edited:

stepalibre

Alibre Super User
Sorry for the delayed responses. Here are a few example addons built using the latest dev tools.
These were pulled out of another solution so there is additional content and references you can remove.

msbuild project type
1700279530303.png

SDK project type
1700280934768.png
 
Top