Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

"Any CPU" can't be changed...

Discussion in 'Windows' started by Maisey, Feb 11, 2016.

  1. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Hello,

    I'm building a Universal App for Windows (and Phone) 10 and as of Unity 5.3.x+ you can no longer change the "Any CPU" option of plugins. How am I supposed to do the following:

    I'm going to add the "Microsoft Ads" to my app and thus I am creating a plugin for it. According to Micrsofts documentation, I need to select either x86 or ARM when building because the library internally (or something) picks the correct classes to use. In other words, when I build my DLL I have to target either x86 or ARM, if I select "No CPU" when building, it will only cause errors (and is explained in the documentation as not possible).

    So, now I have two plugins named My-Plugin.dll (targeting x86) and another My-Plugin.dll (targeting ARM). But placing these inside Unity will cause a conflict and thus I tried changing the SDK of each plugin. So one of them uses "UWP" and the other uses "Phone SDK81" (which is wrong because I'm building for Windows Phone 10).

    The project compiles, but when trying to run it in the C# Project it will throw an error and say that I'm building for ARM but the dll being used is built for x86. If I was able to select which CPU to use this would probably not be an issue (not sure though).

    Any suggestions? @Tautvydas Zilys

    Thanks!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    The reason why you can only use AnyCPU managed plugins is because Unity somehow has to choose one when building your scripts. It cannot do so if there's multiple of them. So, you should only need one DLL. I suppose those DLLs are actually identical, apart from differences in compiler settings?

    Does this problem only happen if you build with "C# projects" checkbox selected in Unity? Could you paste build output from VS?
     
  3. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    The DLLs are identical in the meaning that my code is the exact same for both x86 and ARM, but when they are actually built, they differ in size. One is 18kb (x86) the other one is 17kb (ARM).

    I always build to a "C# Project" so I wouldn't know what happen if I don't.

    This is the output when i try to build from VS:

    Code (CSharp):
    1. Severity    Code    Description    Project    File    Line    Suppression State
    2. Error        There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture of the reference "Win10-Ads-Plugin", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.    Assembly-CSharp    
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    Can you show the contents of the output window?
     
  5. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Ahh sorry, misunderstood you @Tautvydas Zilys !

    Here is the output window when trying to build from VS:

    Code (CSharp):
    1. 1>------ Build started: Project: Assembly-CSharp, Configuration: Debug ARM ------
    2. 2>------ Build started: Project: Assembly-CSharp-firstpass, Configuration: Debug ARM ------
    3. 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Assembly-CSharp-firstpass". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    4. 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): error MSB3270: There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture of the reference "Win10-Ads-Plugin", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
    5. 1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Assembly-CSharp-firstpass". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    6. 1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): error MSB3270: There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture of the reference "Win10-Ads-Plugin", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
    7. 3>------ Build started: Project: ACELib-Ads-Unity, Configuration: Debug ARM ------
    8. 3>  UnityInstallationDir "D:\Program Files\Unity 5.3.2p2\Editor".
    9. 3>  UnityWSAPlayerDir "D:\Program Files\Unity 5.3.2p2\Editor\Data\PlaybackEngines\MetroSupport".
    10. 3>  UnityProjectDir "D:\GitHub\acelib-unity\Unity\ACELib-Ads".
    11. 3>  Copying unprocessed assemblies...
    12. 3>C:\Users\Rasmus\Desktop\win10-ads-tmp-builds\2\ACELib-Ads-Unity\ACELib-Ads-Unity.csproj(257,5): error MSB3030: Could not copy the file "D:\GitHub\acelib-unity\Unity\ACELib-Ads\UWP\Assembly-CSharp\bin\ARM\Debug\Unprocessed\Assembly-CSharp.dll" because it was not found.
    13. ========== Build: 0 succeeded, 3 failed, 0 up-to-date, 0 skipped ==========
    14. ========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
    15.  
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    Can you submit a bug report on this? In the meantime, I'll look for a workaround. Please post case # here once you get it.
     
  7. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    I've made a bug report. Awaiting the case #. :)
     
  8. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
  9. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Sorry to hijack my own thread but while creating this plugin i noticed that Unity gives the following error when placing the plugin inside some Unity-folder (the "Platform" for the Plugin is WSAPlayer and "SDK" is UWP, changing the SDK-value will cause the error to be printed once more):

    Code (CSharp):
    1.  
    2. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    3.   at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0
    4.   at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
    5.   at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00000] in <filename unknown>:0
    6.   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
    7.   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
    8.   at Mono.Cecil.TypeReference.Resolve () [0x00000] in <filename unknown>:0
    9.   at AssemblyUpdater.Steps.MemberReferenceReplacer.MemberReferenceReplacementForProperty (Mono.Cecil.MethodReference method) [0x00000] in <filename unknown>:0
    10.   at AssemblyUpdater.Steps.MemberReferenceReplacer.MemberReferenceReplacementFor (Mono.Cecil.MethodReference methodReference) [0x00000] in <filename unknown>:0
    11.   at AssemblyUpdater.Steps.MemberReferenceReplacer.Visit (Mono.Cecil.MethodReference methodReference, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    12.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.Cil.Instruction instruction, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    13.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.Cil.MethodBody methodBody, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    14.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.MethodDefinition methodDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    15.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.TypeDefinition typeDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    16.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.ModuleDefinition moduleDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    17.   at Unity.Cecil.Visitor.Visitor.Visit (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    18.   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
    19.   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    20.   --- End of inner exception stack trace ---
    21.   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    22.   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
    23.   at Unity.Cecil.Visitor.Visitor.Visit[AssemblyDefinition] (Mono.Cecil.AssemblyDefinition node, Unity.Cecil.Visitor.Context context) [0x00000] in <filename unknown>:0
    24.   at Unity.Cecil.Visitor.Extensions.DoAccept[AssemblyDefinition] (Mono.Cecil.AssemblyDefinition definition, Unity.Cecil.Visitor.Visitor visitor) [0x00000] in <filename unknown>:0
    25.   at Unity.Cecil.Visitor.Extensions.Accept (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.Cecil.Visitor.Visitor visitor) [0x00000] in <filename unknown>:0
    26.   at AssemblyUpdater.Steps.AssemblyUpdaterStepBase.Apply (AssemblyUpdater.Core.AssemblyUpdaterContext context) [0x00000] in <filename unknown>:0
    27.   at AssemblyUpdater.Core.AssemblyUpdaterPipeline.RunUpdateRound (AssemblyUpdater.Core.AssemblyUpdaterContext context) [0x00000] in <filename unknown>:0
    28.   at AssemblyUpdater.Core.AssemblyUpdaterPipeline.Run (AssemblyUpdater.Core.AssemblyUpdaterContext context) [0x00000] in <filename unknown>:0
    29.   at AssemblyUpdater.Application.Program.CheckForObsoleteAPIUsage (AssemblyUpdater.Application.CommandLineSpec config) [0x00000] in <filename unknown>:0
    30.   at AssemblyUpdater.Application.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
    31. UnityEditor.DockArea:OnGUI()
    32.  
    I erased all code in the plugin until I found the cause, and this seems to cause the error:

    Code inside the plugin
    Code (CSharp):
    1. private void RunOnAppThread(Action action)
    2.         {
    3.             UnityEngine.WSA.Application.InvokeOnAppThread(() =>
    4.             {
    5.                 //do something
    6.             }, true);
    7.         }
    Any clue as to why this would cause any issues in Unity? @Tautvydas Zilys
     
    Last edited: Feb 11, 2016
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    That's a known bug, but those errors are pretty harmless. It's tracked by case 743463.

    As for your bug report - I just peeked into it. It happens because you marked your plugins as "Don't process". Don't do that (not sure why you thought it was a good idea to do that). Unity would fix up the architecture if you didn't mark it as don't process.

    Unchecking that option makes the project not build, since you have missing dependencies in your project - it cannot find these assemblies:

    Microsoft.AdMediator.Core, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    Microsoft.AdMediator.Universal, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    Microsoft.Advertising.winmd

    I'll be closing the bug since it's not really a bug.
     
  11. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Sorry, @Tautvydas Zilys , if the test case was not correct but I'm still at a loss how to get this working (and still believe it to be some kind of bug).

    If I uncheck "Don't process", I will get error complaining I'm missing some references (as you've said). I've tried adding those to the project and it will still fail to compile, how should I solve this?

    ALSO, even if I did manage to compile, how am I supposed to have two DLLs, one for x86 and one for ARM? How will it choose the correct one? Since the only right choice is "UWP" what can I do?

    Thanks!
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    Could you be more specific?

    It will use the same DLL for all architectures. That's the only supported scenario. If you don't mark it "don't process", Unity will detect that your DLL is compiled as ARM or x86 and will convert it to AnyCPU when you build your project.
     
  13. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    At the moment I'm getting an error saying:

    Code (CSharp):
    1. [...]
    2. Catastrophic failure while running rrw: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.Advertising, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'
    3.    at Unity.SearchPathAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    4.    at Unity.NuGetAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    5.    at Unity.SearchPathAssemblyResolver.Resolve(AssemblyNameReference name)
    6.    at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    7.    at Mono.Cecil.TypeReference.Resolve()
    8.    at Unity.ReferenceRewriter.RewriteTypeReferences.Visit(TypeReference type, String referencingEntityName)
    9.    at Unity.ReferenceRewriter.ReferenceDispatcher.Visit(TypeReference type, String referencingEntityName)
    10.    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethodBody(MethodBody body)
    11.    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethod(MethodDefinition method)
    12.    at Unity.ReferenceRewriter.ReferenceDispatcher.DispatchMethods(TypeDefinition type)
    13.    at Unity.ReferenceRewriter.ReferenceDispatcher.Dispatch()
    14.    at Unity.ReferenceRewriter.RewriteTypeReferences.Run()
    15.    at Unity.ReferenceRewriter.RewriteOperation.Execute(RewriteContext context)
    16.    at Unity.ReferenceRewriter.Program.Main(String[] args)
    17. [...]
    Even if I included the DLLs in my Unity project (Microsoft.AdMediator.Universal, etc). I'm not sure how I will make sure they are "found" or referenced correctly?

    Really not sure how this is gonna work out if Microsoft requires me to use different architectures. But I will try it once I get my "other" (above) issue resolved.

    Thank you!
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    It cannot find Microsoft.Advertising.winmd file. Is it in your project?

    Microsoft requires no such thing. AnyCPU assemblies are fine.
     
  15. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Thanks for your help @Tautvydas Zilys , I managed to get rid of the library issue (I had the DLL file when I needed the .winmd file). But I'm still having issues with the x86 and ARM of my plugin.

    This is taken from the Microsoft Ads documentation (https://msdn.microsoft.com/en-us/library/mt125365.aspx):

    If I choose "Any CPU" when trying to build my DLL it won't work, it's simply not possible, the advertising namespaces won't be recognized and will cause error.

    And if I build my plugin only for x86 and then place it in Unity and then build my project to VS C# Project it will succeed, but once I actually try to build it to the device I will get the same error as my original post; That the plugin-DLL is built for x86 but I'm building for an ARM device.

    I hope this clarifies my issue?

    Thanks again!
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    You don't need to choose "Any CPU" when building your DLL. You can select any of the CPU architectures: Unity will convert it to AnyCPU when you build your project as long as it's not marked as AnyCPU.

    Does this happen even with your DLL not marked as "Don't process"?
     
  17. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Yes @Tautvydas Zilys . I succesfully made a VS C# Project with the DLL not marked as "Don't process" (by adding the missing libraries). But I receive the following output when trying to build to device:
    Code (CSharp):
    1. Restoring NuGet packages...
    2. To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'
    3. 1>------ Build started: Project: Assembly-CSharp-firstpass, Configuration: Debug ARM ------
    4. 1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): error MSB3270: There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture of the reference "Win10-Ads-Plugin", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
    5. 2>------ Build started: Project: Assembly-CSharp, Configuration: Debug ARM ------
    6. 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): error MSB3270: There was a mismatch between the processor architecture of the project being built "ARM" and the processor architecture of the reference "Win10-Ads-Plugin", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
    7. 3>------ Build started: Project: bugreportuwp, Configuration: Debug ARM ------
    8. 3>  UnityInstallationDir "D:\Program Files\Unity 5.3.2p2\Editor".
    9. 3>  UnityWSAPlayerDir "D:\Program Files\Unity 5.3.2p2\Editor\Data\PlaybackEngines\MetroSupport".
    10. 3>  UnityProjectDir "C:\Users\Rasmus\Desktop\bugreport\bugreportuwp".
    11. 3>  Copying unprocessed assemblies...
    12. 3>C:\Users\Rasmus\Desktop\win10-ads-tmp-builds\1\bugreportuwp\bugreportuwp.csproj(260,5): error MSB3030: Could not copy the file "C:\Users\Rasmus\Desktop\bugreport\bugreportuwp\UWP\Assembly-CSharp\bin\ARM\Debug\Unprocessed\Assembly-CSharp.dll" because it was not found.
    13. ========== Build: 0 succeeded, 3 failed, 0 up-to-date, 0 skipped ==========
    14. ========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
    You should be able to repro this by just adding the missing libs to the bug report project and just delete the ARM-dll that I had there and build to a VS C# Project, and try build to an ARM-device.
     
    Last edited: Feb 12, 2016
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    Uhh. Looks like you found a legit issue - for some reason it we fail to convert x86 assemblies to AnyCPU, but converting ARM and x64 assemblies to AnyCPU works just fine (I just tested it locally). I'll fill a bug on this internally, we'll probably fix it in a patch release.

    Could you try compiling your DLL as ARM or x64 instead of x86 as a workaround? It should start working then.
     
  19. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Thank you for confirming the issue! And I can confirm that building my plugin for ARM will work and it will get converted to AnyCPU successfully!

    Thanks again!
     
  20. kokuda

    kokuda

    Joined:
    Feb 18, 2016
    Posts:
    1
    Has the issue of converting x86 to AnyCPU been resolved? I am having a similar issue, but in my case I don't have the code that built the x86 DLL at hand and I don't need to reference it on ARM, but it is still trying to build with it. Is there any way to exclude the DLL on ARM and keep it on x86 if this issue hasn't been resolve?
     
  21. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,521
    Yes, it has been fixed a few patch releases back. Which Unity version are you on? Do you have a managed (written in C#) DLL too?