I’m attempting to build and use a UWP plugin with Unity. I’m creating a stub DLL for Mono. Unity gives me this error as soon as it is brought into the project.
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 :0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in :0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in :0
at Mono.CSharp.Driver.Compile () [0x00000] in :0
at Mono.CSharp.Driver.Main (System.String[ ] args) [0x00000] in :0
The following assembly referenced from C:\Users\garth\Documents\Projects\UnityWithFacebook\New Unity Project\Assets\WinFaceUnit\WinFacePlugin.dll could not be loaded:
Assembly: System.Runtime (assemblyref_index=0)
Version: 4.0.20.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\garth\Documents\Projects\UnityWithFacebook\New Unity Project\Assets\WinFaceUnit).
Could not load file or assembly ‘System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies.
Missing method .ctor in assembly C:\Users\garth\Documents\Projects\UnityWithFacebook\New Unity Project\Assets\WinFaceUnit\WinFacePlugin.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
Can’t find custom attr constructor image: C:\Users\garth\Documents\Projects\UnityWithFacebook\New Unity Project\Assets\WinFaceUnit\WinFacePlugin.dll mtoken: 0x0a00000d
When I build, two more errors appear.
UnityException: Failed to run assembly converter with command -metadata=0 -platform=uap -lock=“UWP\project.lock.json” Temp\StagingArea\Assembly-CSharp.dll -path=“Temp\StagingArea”.
Reading Assembly-CSharp.dll
Settings:
Platform = UAP
SkipMeta = True
64bit = False
RemoveDebuggableAttribute = True
System.IO.FileNotFoundException: Assembly “WinFacePlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null” file not found.
at Unity.UWPAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Unity.UWPAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Unity.ModuleContext.Retarget(TypeReference type, GenericContext context)
at Unity.ModuleContext.Retarget(MethodReference method, GenericContext context)
at Unity.FixReferencesStep.Visit(MethodDefinition method, GenericContext context)
at Unity.FixReferencesStep.Visit(TypeDefinition type)
at Unity.TypeDefinitionDispatcher.DispatchType(TypeDefinition type)
at Unity.TypeDefinitionDispatcher…ctor(ModuleDefinition module, ITypeDefinitionVisitor visitor)
at Unity.FixReferencesStep.ProcessModule()
at Unity.ModuleStep.Execute()
at Unity.FixReferencesStep.Execute()
at Unity.Step.Execute(OperationContext operationContext, IStepContext previousStepContext)
at Unity.Operation.Execute()
at Unity.Program.Main(String[ ] args)
PostProcessUAP.RunAssemblyConverterNoMetadata (System.String assembly, System.String projectLockFile) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessUAP.cs:69)
PostProcessWinRT.RunReferenceRewriter () (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:547)
PostProcessWinRT.Process () (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:118)
UnityEditor.Metro.BuildPostprocessor.PostProcess (BuildPostProcessArgs args) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/ExtensionModule.cs:99)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()
Error building Player: UnityException: Failed to run assembly converter with command -metadata=0 -platform=uap -lock=“UWP\project.lock.json” Temp\StagingArea\Assembly-CSharp.dll -path=“Temp\StagingArea”.
Reading Assembly-CSharp.dll
Settings:
Platform = UAP
SkipMeta = True
64bit = False
RemoveDebuggableAttribute = True
System.IO.FileNotFoundException: Assembly “WinFacePlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null” file not found.
at Unity.UWPAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Unity.UWPAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Unity.ModuleContext.Retarget(TypeReference type, GenericContext context)
at Unity.ModuleContext.Retarget(MethodReference method, GenericContext context)
at Unity.FixReferencesStep.Visit(MethodDefinition method, GenericContext context)
at Unity.FixReferencesStep.Visit(TypeDefinition type)
at Unity.TypeDefinitionDispatcher.DispatchType(TypeDefinition type)
at Unity.TypeDefinitionDispatcher…ctor(ModuleDefinition module, ITypeDefinitionVisitor visitor)
at Unity.FixReferencesStep.ProcessModule()
at Unity.ModuleStep.Execute()
at Unity.FixReferencesStep.Execute()
at Unity.Step.Execute(OperationContext operationContext, IStepContext previousStepContext)
at Unity.Operation.Execute()
at Unity.Program.Main(String[ ] args)
What am I doing wrong with this stub plugin? I’m trying to use 4 versions of this plugin: Mono stub, x86, ARM, and x64. On Unity 5.2.3p3.
This is the entire code contained in the dll.
using System;
namespace WinFacePlugin
{
public static class Face
{
public static void Initialize( Action<Action> winThreadRunner, Action<Action> unityThreadRunner ) {
// Editor stub.
}
public static void Login( Action<bool, string> callback ) {
// Editor stub.
}
}
}
The error was because I made my stub .dll using a Windows Universal project. targeting .NET 4.6.1.
I changed to making a “Classic Desktop” library project, and set my target framework to “Unity 3.5 .net Subset Base Class Libraries”. There were a few Unity options, not sure which one is the best to pick.
Any desktop version of .NET with 3.5 profile should do fine.