Windows 8.1 - System.TypeLoadException when adding SDKs

Hey,

Here’s a fun problem. When creating a blank Unity project with an empty scene, building it to Windows 8.1, and adding certain SDKs in the Visual Studio solution, the project crashes on deployment. It builds fine, but when it starts to run it gets a System.TypeLoadException in the App.xaml.cs constructor App(), at appCallbacks = new AppCallbacks(false);

The error is as follows:

"An exception of type ‘System.TypeLoadException’ occurred in Template.exe but was not handled in user code

Additional information: Requested Windows Runtime type ‘UnityPlayer.AppCallbacks’ is not registered."

The certain SDK in question is the Microsoft Advertising SDK for Windows 8.1. When I remove the reference, the project runs fine again. Add it again, the app crashes. I do not access any of the API of the SDK in any way, simply adding the reference to the project causes the problem.

I am running Unity 4.5.5p5 and the issue occurs whether you build to Windows 8.1 alone or build a Universal 8.1 project. No issues occur if you add the SDK to a blank Windows Store App in Visual Studio (with no relation to Unity). This problem also occurs when adding the AdDuplex Windows 8.1 SDK (installable through NuGet).

What do?

What are your export settings when building from Unity (SDK, C# projects, etc.) ?

XAML C# Solution
SDK 8.1 (also does it if you choose Universal 8.1)
Unity C# Projects and Development Build are unchecked

We have a reported bug that this failure happens using VS2013 Update 4.
Is that the case for you?

Well I do have VS2013 Update 4 installed because it’s essential to have that update in order to even use Universal 8.1. Where can I see this bug report?

Unity libraries for Universal apps are built with VS 2013 Update 3, there may be an incompatibility here

Okay that makes sense. When I didn’t have the required SDKs to build in Universal 8.1 the Microsoft site told me to just upgrade to the latest version (which is Update 4) so I did that. I’ll downgrade to Update 3 and see if that resolves the issue.

I had to completely uninstall Visual Studio 2013 and install Update 3, because apparently you can’t downgrade. In the end, it worked and the project runs fine now even with those references. It seems like it’d be a major pain for anyone stuck in this kind of situation because Microsoft wants you to upgrade to Update 4, which a lot of people would do only to find out (in no obvious way) that they can’t develop properly for Windows 8.1 on Unity.

1 Like

I suppose we’ll have to update then!

What Unity3D versions do you think will get a patch or update for this?
Unity4.5.x or Unity4.6.x? As long as Unity4.6.x gets an update I think people should be fine.

We’ll first need to investigate the issue in the first place - it might be that the VS version might not be actually the issue here. It was a shot in the dark, but it doesn’t mean it’s a correct one :).

I just ran into this too. I thought it was because I updated to Unity 4.6, but now I realize it was because I upgraded VS to Update 4. I guess I’ll have to go back to Update 3. Ugh.

Uninstalled VS with Update 4, and reinstalled with Update 3. It’s still broken, though. I’m not sure what to try at this point. I can no longer build and launch a Unity app on Win 8.1 if the app uses the advertising SDK.

@sotteson Wondering if you have tried Unity4.6 Patch 1? Looks like it had some stuff fixed for Win8 but have not tried it yet.

I just tried 4.6.0p1 and it’s still broken.

We are facing this issue as well. Will try to downgrade visual studio. Currently I’m downgrading unity, because I thought that was the reason.

Does not seem to work with Visual Studio 2013 - Express - Update 3. (win 8.1)

Working solution: Use Visual Studio 2012 - with Win 8.0 as SDK.

Hi,

I got same error. I Have Visual Studio Premium 2013 Update 4 (Version 12.0.31101.00) and Unity 4.6.1p1

Any update on this problem, because downgrading visual studio isn’t an option for me?

Edit. I removed Microsoft Ad SDK reference and got it working. I’ve already filed one bug report on MS ads not working on Windows Phone

Microsoft acknowledged there’s a bug in Visual Studio 2013 Update 4 and it will get fixed in the near future. In the meantime you can either downgrade to Update 3 or manually edit AppxManifest.xml after build (the problem is that UnityPlayer.dll extension is removed and it needs to be readded). If none of this works for you please leave me a private message and I’ll try to help you.

Can you provide some information on how to edit AppxManifest.xml after build?

Here’s how correct AppxManifest.xml file looks like:

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:build="http://schemas.microsoft.com/developer/appx/2012/build" IgnorableNamespaces="build">
  <!--
    THIS PACKAGE MANIFEST FILE IS GENERATED BY THE BUILD PROCESS.

    Changes to this file will be lost when it is regenerated. To correct errors in this file, edit the source .appxmanifest file.

    For more information on package manifest files, see http://go.microsoft.com/fwlink/?LinkID=241727
  -->
  <Identity Name="testtt" Publisher="CN=DefaultCompany" Version="1.0.0.0" ProcessorArchitecture="x86" />
  <Properties>
    <DisplayName>testtt</DisplayName>
    <PublisherDisplayName>DefaultCompany</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Prerequisites>
    <OSMinVersion>6.3.0</OSMinVersion>
    <OSMaxVersionTested>6.3.0</OSMaxVersionTested>
  </Prerequisites>
  <Resources>
    <Resource Language="EN-US" />
  </Resources>
  <Applications>
    <Application Id="App" Executable="Template.exe" EntryPoint="testtt.App">
      <m2:VisualElements DisplayName="testtt" Square150x150Logo="Assets\MediumTile.png" Square30x30Logo="Assets\SmallLogo.png" Description="testtt" ForegroundText="light" BackgroundColor="#000000">
        <m2:smile:efaultTile Wide310x150Logo="Assets\WideTile.png" DefaultSize="square150x150Logo" />
        <m2:SplashScreen Image="Assets\SplashScreen.png" />
      </m2:VisualElements>
    </Application>
  </Applications>
  <Capabilities />
  <Dependencies>
    <PackageDependency Name="Microsoft.VCLibs.120.00.Debug" MinVersion="12.0.21005.1" />
  </Dependencies>
  <Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>UnityEngineDelegates.dll</Path>
        <ActivatableClass ActivatableClassId="UnityEngineDelegates.FunctionDefsDictionary" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityEngineDelegates.PlatformInvoke" ThreadingModel="both" />
      </InProcessServer>
    </Extension>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>UnityPlayer.dll</Path>
        <ActivatableClass ActivatableClassId="UnityPlayer.AppCallbacks" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.StreamListenerContext" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.MulticastSocketContext" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.XamlPageAutomationPeer" ThreadingModel="both" />
      </InProcessServer>
    </Extension>
    <Extension Category="windows.activatableClass.inProcessServer">
      <InProcessServer>
        <Path>CLRHost.dll</Path>
        <ActivatableClass ActivatableClassId="WinRTBridge.Marshalling" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.MethodTools" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.SerializationReader" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.SerializationWriter" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.ObjectInstantiation" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.TypeInformation" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.ArrayTools" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.ScriptingPinnedArray" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.GCHandles" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.GCHandledObjects" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.Utils" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.WinRTBridge" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.UnityEngineObjectTools" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.ExceptionHandling" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="WinRTBridge.MonoBehaviourSerialization" ThreadingModel="both" />
      </InProcessServer>
    </Extension>
  </Extensions>
  <build:Metadata>
    <build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v4.5.1" />
    <build:Item Name="VisualStudio" Version="12.0" />
    <build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Ultimate 2013" />
    <build:Item Name="OperatingSystem" Version="6.3.9600.16384 (winblue_rtm.130821-1623)" />
    <build:Item Name="Microsoft.Build.AppxPackage.dll" Version="12.0.30501.0" />
    <build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="12.0.30501.0" />
    <build:Item Name="MakePri.exe" Version="6.3.9600.17029 (winblue_gdr.140219-1702)" />
  </build:Metadata>
</Package>

It’s located in bin<x86|ARM><Debug|Release|Master>

Check that this part is not missing:

    <InProcessServer>
        <Path>UnityPlayer.dll</Path>
        <ActivatableClass ActivatableClassId="UnityPlayer.AppCallbacks" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.StreamListenerContext" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.MulticastSocketContext" ThreadingModel="both" />
        <ActivatableClass ActivatableClassId="UnityPlayer.XamlPageAutomationPeer" ThreadingModel="both" />
      </InProcessServer>
2 Likes