- Home /
C++/CLI DLL import error
Recently I am making a UI asset for Unity
. I used Unity 2020.1.0f1
for making and testing primarily. I now have a project in Unity 2021.1.3f1
and I want to use my UI asset. This asset is a unitypackage
and contains 3 DLLs (1 C# DLL, 2 C++/CLI DLLs) with some sample element prefabs and sprites. The CLI DLLs are compiled with /clr:safe
. When I import the asset, Unity
compiles for a couple of seconds and then gives the error
First Error Message:
Could not load image dll-path due to Invalid Section Aligmnent 1000
Run the peverify utility against this for more information.
Second Error Message:
Loading assembly failed:
"dll-path" reason: File does not contain a valid CIL image
I have hid the DLL path for privacy reasons, you will see dll-path
. The DLL appears in the Project
window but if I try to add any MonoBehaviour
contained in those DLLs, it does not show up in the Add Component
menu.
NOTE: I am referencing UnityEngine.dll
, UnityEditor.dll
, UnityEngine.UI.dll
and Unity.TextMeshPro.dll
. All these references were linked when I compiled the DLL with Visual Studio 2019
. Also Note that this asset works fine in Unity 2020.1.0f1
with a new project.
If I am right, I think that this error occurs because of the UnityEngine.dll
and UnityEditor.dll
version conflicting (or I don't know what) with newer version of the same DLL.
EDIT: I also tested with Unity 2020.3.8f1
which is the latest LTS release at the time of writing this question. I doesn't work in any Unity
version except 2020.1.0f1
in which I initially made the DLLs.
If anyone knows, please help me because I am stuck in this situation for hours and I don't want to waste many days because of this error.
Your answer
Follow this Question
Related Questions
Converting from c# string to c++ string 1 Answer
The type or namespace name... again 0 Answers
Failed to load DLL with error "The specified module cannot be found." 1 Answer
Shared memory between c# and c++ 1 Answer
return char** from C++ DLL 0 Answers