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

Unhandled Exception: System.TypeLoadException after I put a plugin.

Discussion in 'Windows' started by hwjwill, Jun 19, 2015.

  1. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    I'm developing a simple game running on Surface Pro 3, and need the gyro data from surface pro. I'm following this tutorial https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/writing-plugins and created a plugin to return the gyro data. Yet when I try to access its methods through the plugin, the compilation fails with following error message:

    Unhandled Exception: System.TypeLoadException: Could not load type 'gyroTest.myGyro' from assembly 'gyroTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

    I think it's because I use Windows.Devices.Sensors in the plugin, which Unity does not supports, but I'm not quite sure how to solve it. Thank you!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
  3. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    Just to clarify the error occurs in Editor when you click Play, or when building to Windows Store Apps ?
     
  5. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    It happens when I click Play
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    So to clarify, you have one plugin for Editor and one plugin for Windows Store Apps, Editor plugin shouldn't be accessing any of the WinRT APIs and is compiled against .NET 3.5, also Editor plugin should be marked as Editor only plugin in the Plugin Inspector, is that correct?
     
  7. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    I made the Editor plugin not access any WinRT APIs and the error doesn't happen anymore. Every other setting is according to the link you posted. However, since the editor plugin is not accessing WinRT APIs anymore, I removed the code that requires Win API and put it as the Editor Plugin, and the objects in Unity behaves according to the Editor version instead of Plugins/WSA/plugin's version. Can you point out where I did wrong?
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    If you're testing the game in Editor, then yes, it's expected that they use Editor plugin and the functionality will be used from Editor plugin rather than Plugins/WSA/plugin's.

    Plugin from Plugin\WSA folder will only be used, when you're actually build to Windows Store Apps, start VS project and run the game.

    If that's not the case, maybe you can send a copy of your project ?
     
  9. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    Hi Thomas, I tried to build for WSA as VS project but it still fails with new error messages. The link is to the zip file of the project,
    https://www.dropbox.com/s/nmakf0ds683vxo1/gyroSurfacePro.zip?dl=0
    it simple try to read x accelerometer data from Surface Pro and print it on the screen.

    Thank you.
     
  10. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    It seems to work fine for me with Unity 5.1.1p2 using Windows SDK 8.1, which Unity version are you using?
     
  11. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    I used Unity 5.1.0f3 and Windows SDK 8.1 These are the errors I got:
    Screenshot (1).png Screenshot (2).png

    C:\TempFolder is where I build the project to.
     
  12. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    It seems you're using Build And Run function, what about Build->Open Visual Studio->Build from there?

    Also, try updating to latest patch release, maybe whatever it was, was fixed in patch release.
     
  13. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    I tried to build in Visual Studio, build doesn't have any errors, but once I clicked Play Local Machine, its output is: Screenshot (3).png

    Then I did according to: https://cyanbyfuchsia.wordpress.com...e-arm-but-this-computer-has-architecture-x64/

    And get more errors:
    Screenshot (4).png
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Don't change it in the configuration properties. Change it in the dropdown menu that's in the upper part of the screenshots, just below "ANALYZE" menu.
     
  15. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    It creates same problem as the second screen shot.
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Click on output tab in Visual Studio. It will contain more info on what's wrong.
     
  17. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    Here is the output after I clicked build:


    1>------ Build started: Project: gyroSurfacePro, Configuration: Debug x64 ------
    1> UnityInstallationDir "C:\Program Files\Unity\Editor".
    1> UnityWSAPlayerDir "C:\Program Files\Unity\Editor\Data\PlaybackEngines\metrosupport".
    1> UnityProjectDir "C:\Users\VRSurface\Documents\vrclub\gyroSurfacePro".
    1> Copying unprocessed assemblies...
    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "UnityPlayer". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "WinRTBridge". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "BridgeInterface". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "UnityEngineDelegates". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "UnityEngineProxy". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    1>C:\Users\VRSurface\Documents\gyroSurfacePro\gyroSurfacePro\App.xaml.cs(19,7,19,18): error CS0246: The type or namespace name 'UnityPlayer' could not be found (are you missing a using directive or an assembly reference?)
    1>C:\Users\VRSurface\Documents\gyroSurfacePro\gyroSurfacePro\MainPage.xaml.cs(21,7,21,18): error CS0246: The type or namespace name 'UnityPlayer' could not be found (are you missing a using directive or an assembly reference?)
    1>C:\Users\VRSurface\Documents\gyroSurfacePro\gyroSurfacePro\App.xaml.cs(29,11,29,23): error CS0246: The type or namespace name 'AppCallbacks' could not be found (are you missing a using directive or an assembly reference?)
    1>C:\Users\VRSurface\Documents\gyroSurfacePro\gyroSurfacePro\MainPage.xaml.cs(30,11,30,22): error CS0246: The type or namespace name 'WinRTBridge' could not be found (are you missing a using directive or an assembly reference?)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Looks like the project is corrupted - it cannot find Unity files. Could you try building from Unity again to an empty folder?
     
  19. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    It's not corrupted, you're building Debug x64 configuration, which is not supported, switch to Debug X86
     
  20. hwjwill

    hwjwill

    Joined:
    Jun 19, 2015
    Posts:
    16
    THANK YOU THOMAS! It finally works.