Issues loading .NET 8 Assembly into Matlab R2023a

I am struggling with loading a .NET 8, C# dynamic library assembly into Matlab.

I’ve tried the following:

  1. Creating a framework-dependent library. This is results in an error where Matlab cannot find System.Runtime

    Message: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
    Source: mscorlib
    HelpLink: None
    
  2. Creating a self-contained library. This seems to load some of the .NET 8 assemblies but eventually fails with the error:

    Message: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
    Source: mscorlib
    HelpLink: None
    
  3. Creating an AOT compatible, self-contained library. This throws the following error. The DLL file referenced in the warning is the DLL of my library project.

    Message: Could not load file or assembly 'file:///<DllFilePath>' or one of its dependencies. The module was expected to contain an assembly manifest.
    Source: mscorlib
    HelpLink: None
    

After attempting the load (any of the loads), I check the .NET environment in Matlab and I get the following:

>> dotnetenv

ans = 

  NETEnvironment with properties:

            Runtime: framework
             Status: loaded
            Version: ".NET Framework 4.0.30319.42000"
    RuntimeLocation: "C:WindowsMicrosoft.NETFramework64v4.0.30319"

Why is it loading the .NET Framework if the assembly is .NET 8?

Since the error occurs during loading, there’s nothing for Visual Studio debugger to attach to in order to use something like AssemblyResolve. I downloaded Fusion++ and have been trying to diagnose the way Matlab is attempting to load these assemblies.

I’m wondering if loading the System namespace by partial name is part of the problem. Is it possible that since it’s not fully qualified it is finding the .NET Framework assembly in the GAC as opposed to using the .NET 8 assembly provided with the library? Is there a way to steer the Matlab loader to the correct assembly?

Here is an excerpt from the Fusion log for the System namespace.

*** Assembly Binder Log Entry  (5/9/2024 @ 12:46:00) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll
Running under executable  <MatlabDir>MATLAB64_bitR2023abinwin64MATLAB.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///<MatlabDir>/MATLAB/64_bit/R2023a/bin/win64/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MATLAB.exe
Calling assembly : dotnetcli, Version=1.0.8570.32197, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: <MatlabDir>MATLAB64_bitR2023abinwin64MATLAB.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///<MatlabDir>/MATLAB/64_bit/R2023a/bin/win64/System.DLL.
LOG: Attempting download of new URL file:///<MatlabDir>/MATLAB/64_bit/R2023a/bin/win64/System/System.DLL.
LOG: Assembly download was successful. Attempting setup of file: <MatlabDir>MATLAB64_bitR2023abinwin64SystemSystem.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: <MatlabDir>MATLAB64_bitR2023abinwin64MATLAB.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Post-policy reference: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:WINDOWSMicrosoft.NetassemblyGAC_MSILSystemv4.0_4.0.0.0__b77a5c561934e089System.dll.
LOG: Assembly is loaded in default load context.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật