Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by abigail_unity393 · Aug 20, 2018 at 09:13 AM · .netnative pluginc++

Does Unity support mixed assemblies (with both native and .Net code) in a single DLL?

Hi,

I have a DLL written in C++. It also contains a .NET API written in C++/CLI, and these are linked together in a single DLL. The C++ code uses some Win32-specific calls, so I'm happy to be restricted to Windows platforms for now.

From any regular C# project in Visual Studio, I can just add it as a reference and use the .NET API to seamlessly interact with the library - no need for P/Invoke, DllImport or writing a C API.

However, when I import it as an asset into a Unity project, it's recognized as a native plugin, and I can't use the C# API from any scripts in the project - they all behave as if the DLL doesn't exist. The C++/CLI code is compiled against .Net Framework 4.0, so I've set the Scripting Runtime Version to '.NET 4.x Equivalent', and the Api Compatibility Level to '.NET 4.x'.

I tried working around this by writing a C# library in Visual Studio that references the mixed C++/.Net library, and then importing both this C# library and the mixed library into the Unity project. When I do that the scripts in the Unity project compile, but the entire editor crashes when I press play.

Are mixed assemblies just not supported in Unity? If so, I couldn't find this documented anywhere. If they are, how can I figure out why Unity is treating my mixed assembly DLL as a native plugin rather than a managed plugin?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image in2sight · Feb 06, 2019 at 08:22 AM 0
Share

Hi, I am having same issue. Does anybody knows a solution? Best regards $$anonymous$$,Hi, I am having the same problem. Does anybody knows an answer?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AP-IGD · Jun 20, 2019 at 12:53 PM

Same problem here, even after a year of having so many followers and no answers....


Hi everyone, no solution but some debugging insights.


I've tried the same thing (Unity 19.3.0a5 x64, Visual Studio 2017) and got the same result. As recommended by MS I've written a CLR (mixed) assembly to wrap my native c++11 lib. To be fully C# compliant, I've written the intermediate C# assembly, basically wrapping only the needed mixed classes/methods. All C# applications I've created/tested, don't cause any problems. Even with multi-threading, hardware controlers etc. no warnings, errors or crashes...


  1. Try, debugging in Editor: Calling the C# lib from a Unity script crashes the editor... I've debugged the whole thing (attached VS debugger to Unity Editor using my libs compiled in debug) and the crash occurs immediatly when my C# lib calls the mixed library (actually its code is never reached...). To be more precise: during some dynamic class generation magic in the mono libs seemingly an error occurs, an exception message is generated and a log-file-write is called. Then good old c-style 'abort()' is called, not very -Stroustrup-...

  2. Try, generating VS solution and debug only my part in pure C. Unfortunatly, 'File'->'Build setting...'->'Build' generation fails with the message

"...But the dll is not allowed to be included or could not be found." (the mixed one is meant here)

Since I've copied the lib to nearly all directories included in path and the project folders, I don't think it's not found. Remaining question:

Why is the library not allowed to be included?

I can only guess, that there's some kind of versioning conflict. .Net, C system libs orororor. I've not found any documentation on that.


This leaves me with to questions to the comunity:

: Does someone here has any info on the exact versions fot .Net, C-std... used by Unity?

: (Most likely answer is NO) Any guess how to wrap native C++ to Unity WITHOUT using global C functions, void pointer and all these unsafe (defined name by MS) methods?


I've quite some experience with tracking down bugs, versioning problems and all that. But, the long work and the complete absence of an error message makes me think, that I've found my master-of-problems...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

92 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity iOS - "Assertion at reflection.c:6869" only in Development Build 0 Answers

Texture2D manipulation in c++ dll Plugin 0 Answers

DllNotFoundException while using unity native c++ Plugins 0 Answers

C++ native plugin Failed with error '%1 is not a valid Win32 application 0 Answers

How can I get the Native Plugin example to work on Unity 5? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges