Force Max to load local assemblies


#1

It seems Max will use C# referenced assemblies which I added to the Visual Studio, not from the local Max folder. For example in C# if I add autodesk.max.dll from 2020 folder, my code works very well in Max 2020, But will crash if I run the code in Max 2016 and If I add from 2016, It will crash the Max 2020. Note that making VS “Local Copy” option to False will not solve the problem.
To register system notification in Autodesk.max.dll 2020, we should use INotifyInfo for the proc argument type, So I have to use polymorphism for the proc methods. My expectation is the Max should run related method based on local autodesk.max.dll, but it will use what I added to the VS.

using Autodesk.Max;
using Autodesk.Max.Wrappers;
using System;

namespace TestLibrary
{
    public class TestClass
    {
        // 3dsMax 2016
        private void proc_ScenestateRename(IntPtr obj, IntPtr info)
        {
            INotifyInfo iNotifyInfo = GlobalInterface.Instance.NotifyInfo.Marshal(info);
            NameChange name = (NameChange)CustomMarshalerNameChange.GetInstance(null).MarshalNativeToManaged((IntPtr)iNotifyInfo.CallParam);
            GlobalInterface.Instance.TheListener.EditStream.Printf("From 2016: " + name.Newname + "\n", null);
        }

        // 3dsMax 2020
        private void proc_ScenestateRename(IntPtr obj, INotifyInfo iNotifyInfo)
        {
            NameChange name = (NameChange)CustomMarshalerNameChange.GetInstance(null).MarshalNativeToManaged((IntPtr)iNotifyInfo.CallParam);
            GlobalInterface.Instance.TheListener.EditStream.Printf("From 2020: " + name.Newname + "\n", null);

        }

        public void Run()
        {
            GlobalInterface.Instance.RegisterNotification
            (
                new GlobalDelegates.Delegate5(this.proc_ScenestateRename),
                null,
                SystemNotificationCode.ScenestateRename
            );
        }
    }
}

#2

you start max from inside VC for testing your c# things ?

i’m not a C# guy, but usually this a “Working Directory” issue
in VC try setting: Configuration Properties - Debugging - Working Directory to your max-folder