Could not load System.Data.OleDb (9.0.0.8) in .NET 8 Add-In for Inventor 2025

Could not load System.Data.OleDb (9.0.0.8) in .NET 8 Add-In for Inventor 2025

marlondiego
Observer Observer
44 Views
0 Replies
Message 1 of 1

Could not load System.Data.OleDb (9.0.0.8) in .NET 8 Add-In for Inventor 2025

marlondiego
Observer
Observer

 

Hello Autodesk community,

I’m developing an Inventor 2025 Add-In using .NET 8. My add-in needs to access an Access database (.accdb), and I’m using the System.Data.OleDb NuGet package version 9.0.8:

 

<PackageReference Include="System.Data.OleDb" Version="9.0.8" />

After building the project, my post-build step copies the compiled DLL and the .addin file to the Inventor Add-Ins folder:

 

<!-- Copy compiled DLL -->
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\ProgramData\Autodesk\Inventor 2025\Addins\" SkipUnchangedFiles="true" />
<!-- Copy .addin file -->
<Copy SourceFiles="$(ProjectDir)Autodesk.MD_PowerTools.Inventor.addin" DestinationFolder="C:\ProgramData\Autodesk\Inventor 2025\Addins\" SkipUnchangedFiles="true" />

My code looks like this (database path updated):

 

using System;
using System.Data.OleDb;

namespace MD_PowerTools.Helpers
{
    public class ProvisionalCodeGenerator
    {
        private static readonly char[] Base36Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
        private static readonly char[] Base26Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

        public int GetUserId(string username) => GetUserIdFromAccess(username);

        public string GenerateCode(int userId)
        {
            string userCode = ToBaseN(userId - 1, Base36Chars, 2);
            DateTime startDate = new DateTime(2025, 1, 1);
            int dayNumber = (DateTime.Now.Date - startDate).Days + 1;
            string dayCode = ToBaseN(dayNumber, Base36Chars, 3);
            int msOfDay = (int)(DateTime.Now - DateTime.Now.Date).TotalMilliseconds;
            string msCode = ToBaseN(msOfDay, Base26Chars, 6);
            return userCode + dayCode + msCode;
        }

        private int GetUserIdFromAccess(string username)
        {
            string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\NewPath\tgt_tic_tac.accdb;";
            string query = "SELECT id_usuario FROM t_usuario WHERE username = ?";

            using var connection = new OleDbConnection(connectionString);
            using var command = new OleDbCommand(query, connection);
            command.Parameters.AddWithValue("username", username);

            connection.Open();
            object result = command.ExecuteScalar();
            if (result != null && int.TryParse(result.ToString(), out int id))
                return id;
            else
                throw new Exception("User not found in t_usuario.");
        }

        private static string ToBaseN(long value, char[] alphabet, int length)
        {
            int n = alphabet.Length;
            char[] result = new char[length];
            for (int i = length - 1; i >= 0; i--)
            {
                result[i] = alphabet[(int)(value % n)];
                value /= n;
            }
            return new string(result);
        }
    }
}

When I click the button in the Inventor API to execute ProvisionalCodeGenerator, I get this error:

 

Could not load file or assembly 'System.Data.OleDB, Version=9.0.0.8, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
System could not find the specified file.

It seems that after the DLL is copied to the Inventor Add-Ins folder, it cannot find the OleDb assembly.

Questions:

  1. Is there a known issue with System.Data.OleDb version 9.0.8 and Inventor 2025 Add-Ins using .NET 8?

  2. Is there a way to ensure the OleDb DLL is correctly loaded when running inside Inventor, even though it’s present in the build output?

  3. Are there recommended workarounds to access an Access database from a .NET 8 Add-In in Inventor without downgrading to .NET Framework?

Thank you very much for any guidance or suggestions!

0 Likes
45 Views
0 Replies
Replies (0)