NativePlugin Changes in 5.2.X broke the Simplest Plugin Example

Simplest Plugin
This plugin project implements only some very basic operations (print a number, print a string, add two floats, add two integers). This example may be helpful if this is your first Unity plugin. The project can be found here and includes Windows, Mac, and Linux project files.

http://docs.unity3d.com/uploads/Main/SimplestPluginExample-4.0.zip

Unfortunately, the SimplestPluginExample doesn’t work in 5.2.1 or 5.2.2.

Loading the most basic plugin results in the following errors.

Failed to load ‘Assets/Plugins/ASimplePlugin.dll’, expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

Failed to load ‘Assets/Plugins/ASimplePlugin.dll’, expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

Failed to load ‘Assets/Plugins/ASimplePlugin.dll’, expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

Failed to load ‘Assets/Plugins/ASimplePlugin.dll’, expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

Failed to load ‘Assets/Plugins/ASimplePlugin.dll’, expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.
PluginImport:Start() (at Assets/PluginImport.cs:25)
PluginImport:Start() (at Assets/PluginImport.cs:21)

DllNotFoundException: Assets/Plugins/ASimplePlugin.dll
PluginImport.Start () (at Assets/PluginImport.cs:21)

Reported in the bug reporter.

(Case 739744) Native Plugins Aren’t working in 5.2.1 or 5.2.2

Tested on WIndows 10 (64-bit)

Have you tried recompiling the plugin for 64-bit?

1 Like

Yes I tried 64-bit. But there’s a few places that I had to change. First I needed to add the x64 target. Then in configuration settings to make sure that target was being built. And then in the project general settings, add x64 output folders. And then linker->Advanced set the target machine to MachineX64. Okay that did it. Maybe add the x64 target to the referenced project. Not sure why 32-bit wouldn’t load?

Not being able to load 32-bit plugins seems like a problem. Not every plugin needs to be 64-bit right?

Especially since i can’t get the 64-bit libraries in some cases.

I discovered a 64-bit loading issue. After compiling for x64, if any code calls a 64-bit static library, the native plugin will not load.

Failed to load ‘Assets/Plugins/EmotivPlugin.dll’ with error 'The operation completed successfully.
', GetDllDirectory returned ‘’. If GetDllDirectory returned non empty path, check that you’re using SetDirectoryDll correctly.

Failed to load ‘Assets/Plugins/EmotivPlugin.dll’ with error 'The operation completed successfully.
', GetDllDirectory returned ‘’. If GetDllDirectory returned non empty path, check that you’re using SetDirectoryDll correctly.
EmotivPlugin:Awake() (at Assets/EmotivPlugin.cs:13)
EmotivPlugin:Awake() (at Assets/EmotivPlugin.cs:12)

DllNotFoundException: Assets/Plugins/EmotivPlugin.dll
EmotivPlugin.Awake () (at Assets/EmotivPlugin.cs:12)

I think this has something to do with linking to a static library and calling from a native plugin.

Reported as case # with attached repro project.

(Case 740144) Unity 5.2.2 Is not able to load native plugins that use static libraries

Solved the 64-bit issue. Not only did I need to statically link with the lib but I needed the premium edk.dll in the Assets/Plugins folder.