How do I resolve a mixed mode assembly error when using .NET Assemblies in a standalone application?

I am trying to use a .NET assembly in my application. When I run the application in the MATLAB Editor, the assembly works fine. However, when I compile my application into a standalone application, I get the following error when I try to call functions in the .NET Assembly:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information
How can I resolve this error?

 Accepted Answer

This error is caused when an application attempts to use a .NET Assembly that was built for a version lower than the application is currently configured to support. In this case, the error is generated because the standalone application is not configured to allow the use of assemblies built with version 2.0.50727 of the .NET framework. On the other hand, the application may work when executed through MATLAB because MATLAB has been configured to be able to load .NET assemblies built with this version of the .NET Framework.
To work around this, a configuration file must be included with the application that specifies the lowest version of the .NET Framework from which assemblies can be loaded. The attached "CHANGEME.exe.config" includes a configuration that will allow a standalone application to load .NET assemblies built with v2.0.50727 of the .NET framework.
To use this file: 
  1. Change its name to match the name of the deployed standalone executable. For example, if your application is named "MyApplication.exe" the configuration file must be named "MyApplication.exe.config"
  2. Ensure that the configuration file is in the same directory as the standalone executable.
    • To include this file in the correct location when the standalone application is installed, add it to the "Files installed for your end user" section of the MATLAB Compiler project.

More Answers (0)

Products

Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!