Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Tyson.9 · Oct 28, 2010 at 08:41 AM · monotypeloadexception

Mono 2.0 subset, precompiled .NET dlls, and TypeLoadExceptions

Within our Unity projects we are using a collection of .NET assemblies that are compiled from our source code within VS2010. Ideally we would compile these assemblies against the supplied Unity/Mono .NET subset core assemblies within Unity, but VS does not allow this, so they are compiled against the standard .NET 3.5 assemblies.

We only want to use the 2.0 subset option for Unity Windows, as we want to make it cross compatible with Web, iPhone, Android, etc.

If a script references a type within these assemblies, that in turn directly references a system type not available in the Mono 2.0 subset assemblies, a compile error is raised within the Unity editor.

However, more indirect references (script -> assembly A -> assembly B -> standard .NET type not available in subset) works within the editor! Adding some logging I noticed it is resolving the type from the full Mono directory (\Mono\lib\mono\2.0), rather than the subset directory (\Mono\lib\mono\unity).

This obviously fails once the project has been deployed and run externally to the editor. Additionally, reflecting over one of these assemblies will cause similar issues on the deployed version, but not within the editor.

So firstly, you may have a possible bug in the compiler and/or type/reference resolving. Secondly, it is rather tedious trying to work out what is and isn't available by deploying, looking at the log, and seeing a general 'System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded' exception. Could Unity3D staff possibly provide me with documentation of what is available in the 2.0 subset build option? Or if someone has a better idea of how to approach this task, it would be greatly appreciated.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Lucas Meijer 1 · Feb 08, 2011 at 01:40 PM

Unity has several different classlib "profiles". We have "2.0" "unity" and "unity_web". We compile your sourcecode against the profile you selected in the playersettings.

The editor itself is built against 2.0, and due to technical reasons, that means your gamecode, while compiled against the right profile, will run against 2.0. (which is a superset of all other profiles, which is why this works).

Since you compile your assembly in visualstudio, visualstudio can compile against the full 2.0 profile, and it is indeed misleading that such an assembly in the editor actually works, but will fail to build. It would be nicer if we could warn about this earlier.

It is also unfortunate that visual studio does not allow you to compile against a "custom" class library profile. It only lets you compile against the "official" .net2.0, .net3.5 etc classlibs. Unity ships custom class lib profiles, because a lot of the classlib stuff does not make much sense for most games, while it can in some cases add to your filesize.

I don't have a great out of the box solution for you, however, what you could do to smooth your workflow is add a postbuild step to your visualstudio build, that verifies if your generated assembly is referencing any types that do not exist in the "unity" profile. You could write a small program that does this ontop of Mono.Cecil

In the upcomgin Unity3.2 release, we have more detailed information about which types are and are not available in each different profile. Untill that time, you can use a tool like .net reflector to inspect our mscorlib.dll & system.dll & friends to figure out what exactly you are referencing that does not exist.

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
avatar image
0

Answer by Tyson.9 · Nov 15, 2012 at 05:07 AM

Here is the more detailed information Lucas mentions in the answer above:

http://docs.unity3d.com/412/Documentation/ScriptReference/index.Unity_and_Mono_compatibility.html

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

2 People are following this question.

avatar image avatar image

Related Questions

Newly installed 2018.1b fails to start tutorial projects (TypeLoadException) 0 Answers

Will installing a newer mono version break Unity's mono installation ? (OSX) 2 Answers

Where is the Mono C# compiler for Unity iPhone? 1 Answer

Standalone windows build giving mono: dll not found error 2 Answers

mono develop error 1 Answer


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