Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Building for Universal 8.1 SDK: Missing method .ctor in assembly Newtonsoft.Json.dll

Discussion in 'Windows' started by Acrilige, Dec 2, 2015.

  1. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Hi.

    I created a new project and put a Newtonsoft.Json.dll under Assets/Plugins folder. I selected "WSAPlayer" as plugin platform and AnySDK / AnyCPU. Everything builds fine when I'm pressing Build.

    After that I'm adding new C# script to Assets folder (just default one, using menu "Create - C# script". Now when I'm trying to build that project I'm getting this:

    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

    Missing method .ctor in assembly C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\Metro\Newtonsoft.Json.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
    The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in Newtonsoft.Json
    Can't find custom attr constructor image: C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\Metro\Newtonsoft.Json.dll mtoken: 0x0a000045


    What's the reason for this? Is this a bug, should I report it? May be something wrong with the Newtonsoft.Json assembly I used? If yes, why this happens only if project has at least one c# script in it?

    Unity version is 5.2.2p4, OS is Windows 10
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    Make sure you use the version of that dll that is compatible with Windows Store Apps.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    This is C# compiler crashing when trying to compile your script. If you have no scripts, it kinda makes sense that you don't see this error.

    Can you show a screenshot of "Assets\Plugins\Metro\Newtonsoft.Json.dll" plugin settings?
     
  4. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50

    Attached Files:

  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    This is the wrong plugin. You showed me "Assets\Plugins\NewtonsoftJon.dll", while the compiler crashed on "Assets\Plugins\Metro\Newtonsoft.Json.dll".
     
  6. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Yes, I just moved it to Assets/Plugins to see if it makes any difference. It doesn't.

    Everything builds fine if I set "Use Net Core" as compilation overrides. As far as I understand it means that everything will be compiled using Microsoft c# Compiler? Does it mean that Mono compiler fails for some reason?
     
  7. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Just to make sure, I tried assembly from portable and portable40 folders. First one gives an error I wrote above, second one gives a different one:

    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

    The following assembly referenced from C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\Newtonsoft.Json.dll could not be loaded:
    Assembly: System.Runtime (assemblyref_index=0)
    Version: 4.0.0.0
    Public Key: b03f5f7f11d50a3a
    The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\).

    Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    Missing method .ctor in assembly C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\Newtonsoft.Json.dll, type System.Reflection.AssemblyProductAttribute
    Can't find custom attr constructor image: C:\Users\SuchUser\Development\WindowsStoreTest\Assets\Plugins\Newtonsoft.Json.dll mtoken: 0x0a00003c
    The class System.Runtime.Serialization.CollectionDataContractAttribute could not be loaded, used in System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Yes, it looks like Mono compiler cannot handle the DLL. Though, I was pretty sure that we should detect that it would fail and not pass it to the compiler at all.

    Any chance you could try latest 5.3 build as well?

    Lastly, we'd like a bug report on this.
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    That explains it. Yes, mono compiler can have issues with .dll's build using Microsoft compiler and targeting newer .NET.

    Why do you want to set overrides to use Mono compiler,. Normally you'd be better with MS compiler.
     
  10. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Yes, I'll try it on 5.3.0f2 and tell you the result

    I don't want to. It's the default option.

    Also I'm almost sure this worked on 4.6 without compilation overrides, but I'll check that too
     
  11. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    I checked it on 4.6.2, created a new project, put Newtonsoft.Json.dll into these folders:
    Assets/Plugins/Metro
    Assets/Plugins/Metro/Win81
    Assets/Plugins/Metro/WindowsPhone81

    Created an empty c# script

    Set compilation overrides to None

    Built for Universal 8.1 sdk, and it went fine.

    I guess that's what Tautvydas Zilys meant by "not passing it to compiler at all"? Since there are no scripts that depend of that assembly, there are no compilation errors? I think that's how it's supposed to be?

    Checking on 5.3.0f2 soon..
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    I'm pretty sure that using Mono compiler is not the default option. Default is "Use .Net Core".

    Basically yes. If you were to try to use that assembly from a script, you'd get type doesn't exist type errors. Mono compiler just doesn't know what to do with that assembly.
     
  13. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Yes, sorry, forgot that I changed it before while testing.
     
  14. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    It's the same way on 5.3.0f2. Should I submit a bug report on this?
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Yes please. Even though it might have to do something with the DLL, I still want to know the reason why our incompatibility detection fails.
     
  16. Acrilige

    Acrilige

    Joined:
    May 6, 2013
    Posts:
    50
    Report id is 750001