The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
ReflectionTypeLoadException Referencing UWP Assembly
Hi everyone, I would like to include a UWP library in my HoloLens app, however I'm getting compile errors that cause my scripts to go missing, as well as the Holotoolkit menu. The Play function in Unity also no longer works when I add the assembly to the resources.
To keep it simple, I created an empty UWP library project, left just the defaults and empty sample Class1.cs. Built it, dragged the resulting assembly into my assets in unity. All errors start here with ReflectionTypeLoadException:
"Could not load file or assembly 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies."
Obviously I've created the library incorrectly. Should it not be a UWP Library project?
Thanks!
Best Answer
-
OptionsHoloSheep mod
@AngryPixel are you using #if directives around your UWP specific calls so that the Unity editor/compiler ignores those lines of code?
The assemblies should be added (referenced) in the UWP project that you build from Unity, you shouldn't be including UWP libraries in the actual Unity project.
I think that is the issue, but apologies if I am misunderstanding you situation.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings5
Answers
Nobody else is referencing an assembly?
@AngryPixel are you using #if directives around your UWP specific calls so that the Unity editor/compiler ignores those lines of code?
The assemblies should be added (referenced) in the UWP project that you build from Unity, you shouldn't be including UWP libraries in the actual Unity project.
I think that is the issue, but apologies if I am misunderstanding you situation.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings
Yes, that did it, I read another article online saying that the correct way to reference assemblies is to add them as resources and they are automatically added as references to the resulting project. That method actually mostly works...
Thanks HoloSheep
Seems I spoke too soon. Is there a method that does not include having to re-add the references every time I want to make a code build for HoloLens deployment?
For Instance, the following produces errors in Unity even though Visual Studio sees the namespaces correctly.
if UNITY_METRO && !UNITY_EDITOR
using CustomNamespace;
else
using UnityNamespace;
endif
Then if I hack this just to get past the Unity code build, re-add my references, I get :
Severity Code Description Project File Line Suppression State
Error The command ""C:\Source\WindowsStoreApp\Unity\Tools\AssemblyConverter.exe" -platform=uap -lock="C:\Source\WindowsStoreApp\PROJECT\project.lock.json" -bits=32 -configuration=Release -removeDebuggableAttribute=False -path="." -path="..\Players\UAP\x86\Release" "C:\Source\WindowsStoreApp\PROJECT\Assembly-CSharp.dll" "C:\Source\WindowsStoreApp\PROJECT\Assembly-CSharp-firstpass.dll" "C:\Source\WindowsStoreApp\PROJECT\UnityEngine.dll" "C:\Source\WindowsStoreApp\PROJECT\UnityEngine.UI.dll" "C:\Source\WindowsStoreApp\PROJECT\UnityEngine.HoloLens.dll" "C:\Source\WindowsStoreApp\PROJECT\UnityEngine.Networking.dll" "C:\Source\WindowsStoreApp\PROJECT\UnityEngine.VR.dll"" exited with code 1. PROJECT C:\Source\WindowsStoreApp\PROJECT\PROJECT.csproj 296
I'm currently of the belief that referenced assemblies really aren't supported. Even if this worked, the workflow is absolutely terrible - having to re-add references each time you make a new Unity build? Yes I know you can prevent the project files from being overwritten, but that still leaves you having to change it so that it does overwrite when you add scripts and re-adding the references, the changing the file back...
What am I missing?
Seriously, the Unity Code Compiler seems to just ignore preprocessor directives completely. It looks like it works completely opposite of the runtime. I can't find a combination of directives that works with both the Run option and Compiler... ??
Thought I would update this thread based on a recent finding:
The UWP Assemblies should be added as Assets to the Unity Project. The previous problem I listed seems to be specific to building the Solution from the HoloTookit menu option whereby it always processes the assemblies even if you check "Don't Process". The following blogpost illustrates a successful way to do this:
https://mtaulty.com/2016/10/25/windows-10-uwp-unity-and-adding-a-reference-to-a-uwp-class-library/