Win Store plugin causing internal compiler error

I have built a simple Windows Store plugin with a single method. It worked, and the functionality worked correctly in my game (I could build and deploy with no issues). However, when I came back to work on the game I was getting errors that seem to be caused by my plugin.

Now I can’t even play the game inside Unity without removing the ‘fake’ DLL, and I can’t build for Windows Store without having the fake DLL there…

Here is the error message:
Internal compiler error. See the console log for more information. output was:
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 

If I delete the fake DLL the error disappears (and I can run the game in the editor).

  • My DLLs are correctly named and share the same namespaces, etc
  • Both game and plugin target Windows 8.1
  • Fake DLL is in the plugins folder, real one is in the Plugins/Metro folder
  • Plugin projects target .net 3.5
  • I’ve used #if NETFX_CORE to wrap code in my plugin and #if UNITY_METRO within Unity scripts
  • FWIW I have a WP8 plugin that is similar and works fine

Here is a repro of my DLL files (I’ve included the full VS solution in case someone is kind enough to check for dumb errors. The built DLLs are in the respective bin/release folders of the two projects. The entire source code is there (it’s just a single method that launches an email).

DLLs that cause internal compiler error

Any ideas what I’ve done wrong? The weird thing is that it worked fine, then suddenly gives this showstopper error.

Are you building your fake dll from a Visual Studio project for a “Windows Store app”? If that is so, I believe VS will reference libraries that don’t exist in Mono, and #if NETFX_CORE won’t save you from this. Even if you try creating a dll from an empty file with no code it still gives errors in Unity.

Seeing how the fake dll is not to be used in Windows Store Apps, it should be outside the Plugins/Metro folder (as you already have) and I think it should be created as a normal desktop library in Visual Studio (I don’t have the VS version for this, however).

Do you really need the fake dll? I’m guessing you want to use it to call empty methods in non-Windows-Store apps, hence the “fake” word. However, you said “I can’t build for Windows Store without having the fake DLL there…”. Maybe that is because you use #if UNITY_METRO in your scripts, and should instead use #if NETFX_CORE, because UNITY_METRO is active in the Editor when you have Windows Store apps as a target, causing Unity to try to use your plugin and failing.

In places where you need to reference the “true” dll in your scripts, you should use #if NETFX_CORE, and a fake dll shouldn’t be necessary.