Search code examples
c#unity-game-engineqr-codehololenswindows-mixed-reality

Getting COM Exception in Unity after adding missing dll. MixedReality QR Code Sample for HoloLens 2


This is the Error Message I get:

COMException
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) (at <9577ac7a62ef43179789031239ba8798>:0)
WinRT.Platform.RoGetActivationFactory (System.IntPtr runtimeClassId, System.Guid& iid) (at <018a8dd1eaa44ac38faac041d704e74c>:0)
WinRT.WinrtModule.GetActivationFactory (WinRT.HString runtimeClassId) (at <018a8dd1eaa44ac38faac041d704e74c>:0)
WinRT.ActivationFactory`1[T]..ctor () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Activator.CreateInstance[T] () (at <9577ac7a62ef43179789031239ba8798>:0)
WinRT.WeakLazy`1+<>c[T].<.ctor>b__2_0 () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
WinRT.WeakLazy`1[T].get_Value () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
WinRT.ActivationFactory`1[T].As[I] () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
Microsoft.MixedReality.QR.QRCodeWatcher+Statics..ctor () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <9577ac7a62ef43179789031239ba8798>:0)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Activator.CreateInstance[T] () (at <9577ac7a62ef43179789031239ba8798>:0)
WinRT.WeakLazy`1+<>c[T].<.ctor>b__2_0 () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
WinRT.WeakLazy`1[T].get_Value () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
Microsoft.MixedReality.QR.QRCodeWatcher.RequestAccessAsync () (at <018a8dd1eaa44ac38faac041d704e74c>:0)
QRTracking.QRCodesManager+<Start>d__29.MoveNext () (at Assets/Scripts/QRCodesManager.cs:83)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <9577ac7a62ef43179789031239ba8798>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <9577ac7a62ef43179789031239ba8798>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <e414e10bfe5f45729ff122f3359de21b>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

I got the Error after adding vcruntime140_app.dll to my plugins folder.

This is the code that seems to cause the error:

        async protected virtual void Start()
        {
            IsSupported = QRCodeWatcher.IsSupported();
            capabilityTask = QRCodeWatcher.RequestAccessAsync();
            accessStatus = await capabilityTask;
            capabilityInitialized = true;
        }

This is from the offical mc example code (https://github.com/microsoft/MixedReality-QRCode-Sample). I have imported the scripts and prefabs to a fresh mixed reality unity project and am now trying to get this to work.


Solution

  • You need to restore the VC runtime and QRcode NuGet package via NuGet for Unity. Please feel free to refer yl-msft/QRTracking: MRTK sample app for QRtracking (github.com) to modify your current project.