Search Unity

WinRTLegacy conflicts

Discussion in 'Windows' started by noethis, Sep 9, 2015.

  1. noethis

    noethis

    Joined:
    Nov 11, 2013
    Posts:
    129
    I'm trying to build to Win10 from Unity 5.2f3 and keep running into issues with .NET types that have been duplicated in WinRTLegacy (e.g. XmlDocument, System.IO.Directory/File):

    Code (CSharp):
    1.  error CS0433: The type 'Directory' exists in both 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    I've tried a bunch of variants of the suggested fix below, but haven't gotten anything to play nicely when I actually build. I admit I don't fully understand how 'usings' work.

    Code (CSharp):
    1. #if NETFX_CORE
    2. using IO = WinRTLegacy.System.IO;
    3. #else
    4. using IO = System.IO;
    5. #endif
    Any help would be appreciated!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Hi, we're aware of this issue... there is a fix, but it will be only be available in 5.2p2.

    There's no workarounds as far as I know...

    You could submit a bug report with repro case, so we would be sure it fixes your issue as well.
     
  3. noethis

    noethis

    Joined:
    Nov 11, 2013
    Posts:
    129
    Thanks for the response! Do you know approximately when 5.2p1 will be coming out?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    I am guessing it will be released Sep 21.
     
  5. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    If you don't have a lot of code that uses these conflicting classes, you could make this workaround:

    1. Build an empty Unity project for Windows 10, find WinRTLegacy.dll in the built Visual Studio project.
    2. Drop WinRTLegacy.dll into your normal Unity project (Plugins/WSA/). Mark it as "don't process" in Unity and tick only the WSA checkbox.
    3. Add a file named csc.rsp directly in your Assets folder and put this line in it: /reference:WinRTLegacyTMP=Assets/Plugins/WSA/WinRTLegacy.dll
    4. In scripts that use conflicting classes, at the very top, add:

    #if NETFX_CORE
    extern alias WinRTLegacyTMP;
    #endif

    5. In each file that uses conflicting classes for every conflicting class, also add these after other "using" statements:

    #if NETFX_CORE
    using ConflictingClassName = WinRTLegacyTMP::Full.Namespace.ConflictingClassName;
    #endif

    It's not pretty, but if you need to build it and cannot wait for the fix, it's better than nothing.
     
    Last edited: Sep 16, 2015
  6. marcis91

    marcis91

    Joined:
    Sep 16, 2015
    Posts:
    5
    I got same error previously
    Code (csharp):
    1.  error CS0433: The type'File' exists in both 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    With DominoOne solution the error disappeared, but I got new error:
    Code (csharp):
    1.  error CS0234: The type or namespace name 'Full' does not exist in the namespace 'WinRTLegacyTMP' (are you missing an assembly reference?)
    Any solutions?
     
  7. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    You do not need to write "Full" in the namespace :) You just have to write the full namespace instead. E. g. for the File class you have to write:

    #if NETFX_CORE
    using File = WinRTLegacyTMP::System.IO.File;
    #endif

    If you have other conflicting classes, you'll need to write a similar line for each of them.
     
  8. marcis91

    marcis91

    Joined:
    Sep 16, 2015
    Posts:
    5
    Thanks for the quick response :)
    But now the old error popped back and got new error:

    Code (csharp):
    1.  
    2.  
    3. Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
    4.  
    5.   at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
    6.  
    7.   at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
    8.  
    9.   at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
    10.  
    11.   at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
    12.  
    13.   at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
    14.  
    15.   at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
    16.  
    17.   at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
    18.  
    19.   at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
    20.  
    21. The following assembly referenced from C:\YYY\Assets\Plugins\WSA\WinRTLegacy.dll could not be loaded:
    22.      Assembly:   System.Runtime    (assemblyref_index=0)
    23.      Version:    4.0.20.0
    24.      Public Key: b03f5f7f11d50a3a
    25. 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:\YYY\Assets\Plugins\WSA\).
    26.  
    27. Could not load file or assembly 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    28. Missing method .ctor in assembly C:\YYY\Assets\Plugins\WSA\WinRTLegacy.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
    29. Can't find custom attr constructor image: C:\YYY\Assets\Plugins\WSA\WinRTLegacy.dll mtoken:
    30.  
     
  9. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hm.. Did you mark WinRTLegacy.dll as only used for WSA? I didn't mention that in the steps, but I think that was necessary.
     
  10. marcis91

    marcis91

    Joined:
    Sep 16, 2015
    Posts:
    5
    Yes, thanks, that caused that Unhandled Exception error, but the original error unfortunately appears anyway :/

    Code (csharp):
    1.  
    2. Assets\Scripts\AssetStreamer.cs(28,22): error CS0433: The type 'File' exists in both 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
    3.  
    Guess, I should wait for 5.2p1
     
  11. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Could you paste the code of the AssetStreamer.cs script? I could check it out to see if everything's in place for the workaround to work.
     
  12. marcis91

    marcis91

    Joined:
    Sep 16, 2015
    Posts:
    5
    Code (csharp):
    1.  
    2. #if NETFX_CORE
    3. extern alias WinRTLegacyTMP;
    4. #endif
    5.    
    6. using UnityEngine;
    7. using System.Collections;
    8.  
    9. #if NETFX_CORE
    10. using File = WinRTLegacyTMP::System.IO.File;
    11. #endif
    12.  
    13. public class AssetStreamer : MonoBehaviour {
    14.  
    15.     private void Start (){
    16.         string path = Application.dataPath + "/StreamingAssets";
    17.     }
    18.  
    19.     public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
    20.     public string result = "";
    21.  
    22.     IEnumerator Example() {
    23.         if(filePath.Contains("://")) {
    24.        
    25.             WWW www = new WWW(filePath);
    26.             yield return www;
    27.             result = www.text;
    28.         }
    29.         else
    30.             result = System.IO.File.ReadAllText(filePath);
    31.     }
    32. }
    33.  
    I could not paste all code, because forum said that it contains spam-like or inappropriate content, but here is the part that contains error
     
  13. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    OK, since you're using the full namespace before class names (e. g. System.IO.File.ReadAllText(filePath)), try adding this:

    #if NETFX_CORE
    using System = WinRTLegacyTMP::System;
    #endif

    If that doesn't help, you could remove "System.IO." before "File" (e. g. result = File.ReadAllText(filePath);).
     
  14. marcis91

    marcis91

    Joined:
    Sep 16, 2015
    Posts:
    5
    Awesome, that worked. Thanks! :)
    btw I wish luck to Lithuania for tommorows game vs Serbia ;)
     
  15. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    433
    Hehe, thanks! :) Also, great that it finally worked for you.
     
  16. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    Shouldn't this bug be fixed in 5.2p1? I just installed the patch release and the bug still exists.
     
  17. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Sadly that fix missed 5.2.0p1, it should be in 5.2.1p1 which should be released in Sep 23.

    Sorry for inconvience
     
    Last edited: Sep 22, 2015
  18. RJ45

    RJ45

    Joined:
    Mar 27, 2015
    Posts:
    7
    I am also having this issue. I can't seem to get the work around to work. :(
     
  19. RJ45

    RJ45

    Joined:
    Mar 27, 2015
    Posts:
    7
    Is there any way to just remove WINRT legacy? I can rewrite these classes myself I guess.
     
  20. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    It's placed here - Editor\Data\PlaybackEngines\metrosupport\Managed\UAP, I doubt you can remove it, but you probably can provide an empty assembly instead :) No promises, that it'll work though
     
  21. RJ45

    RJ45

    Joined:
    Mar 27, 2015
    Posts:
    7
    Any update on when this will be fixed?
     
  22. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Still 5.2.1p1
     
  23. kshitijgandhi

    kshitijgandhi

    Joined:
    Jul 13, 2015
    Posts:
    28
    Having the same issue. Still waiting for 5.2.1p1 - not out on 24 sep also....
     
  24. RJ45

    RJ45

    Joined:
    Mar 27, 2015
    Posts:
    7
    Still having the same issue on 5.2.1f1 Is this supposed to be fixed in p1? and when will that be out.

    Thanks!
     
  25. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    Finally 5.2.1p1 is out :D But now i have the problem when i use WinRTLegacy i get an error because the namespace WinRTLegacy.IO is missing

    Code (CSharp):
    1. #if NETFX_CORE
    2. using StreamWriter = WinRTLegacy.IO.StreamWriter;
    3. #endif
    4.  
     
  26. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Use regular StreamWriter, something like
    Code (csharp):
    1.  
    2. #if NEFTFX_CORE && !WINDOWS_UWP
    3. using StreamWriter = WinRTLegacy.IO.StreamWriter;
    4. #else
    5. using System.IO;
    6. #endif
    7.  
     
  27. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    I get many errors with the regular StreamWriter on UWP. That's the reason why i wanted to use WinRTLegacy.IO.StreamWriter instead
     
  28. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    What errors ?
     
  29. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    The constructor of StreamWriter is different in .NET Core 5. Also the method Close() is removed, but this can be probably simply fixed by using Dispose() instead.
     
  30. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    WinRTLegacy still contains the StreamWriter class so why is it not working with this patch anymore?
     
  31. TheAtomAnt

    TheAtomAnt

    Joined:
    Apr 13, 2014
    Posts:
    12
    Using Unity 5.2.1f1 and still seeing this issue. I tried DominoOne's solution and it did allow Unity to create the Win10 Universal solution, which I then tried to open in Visual Studio 2015. Visual Studio is now throwing exceptions for each
    externalias WinRTLegacyTMP; usage saying... The extern alias 'WinRTLegacyTMP' was not specified in a /reference option

    I see the csc.rsp file in the Assets folder, I even tried to add it to the project, but it seems like the solution is ignoring it when it tries to build.

    Any other thoughts?
     
  32. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I've been struggling ever since U5.2.0 got released to get StreamWriter to work... and after all this time you are telling me the solution was simply to sit back and wait then download a new version of Unity? Omg... If only I had known this from the beginning....

    Let me go download the latest version and see if my (proven)working code finally compiles again! +1 on this bandwidth heavy but simple solution! :D

    P.s. I am new to Windows development and the porting guides just say "Coming soon". Any idea when "soon" might be?

    Thanks
     
  33. TheAtomAnt

    TheAtomAnt

    Joined:
    Apr 13, 2014
    Posts:
    12
    Think I might have gotten it... I needed to right click the WinRTLegacy DLL and select properties. Then I changed the Aliases to WinRTLegacyTMP. Many of the errors went away - leaving me with unrelated errors. I'll continue trying to fix those and hopefully get a compiling WinUniversal 10 app!
     
  34. Eknoes

    Eknoes

    Joined:
    Sep 15, 2015
    Posts:
    56
    @pliska.adam Try Unity 5.2.1p1 then you should not need the workaround anymore
     
  35. kshitijgandhi

    kshitijgandhi

    Joined:
    Jul 13, 2015
    Posts:
    28
    The type 'SocketErrorStatus' exists in both 'Windows.Foundation.UniversalApiContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' and 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'

    Many of the errors are gone, but errors like this still exist. Any solution for these errors? These seem similar to the WinRTLegacy issues...
     
  36. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    I'm getting a similar issue with 'IOrderedDictionary':

    Assets\Shared\AWSSDK\src\Core\ThirdParty\Json\IJsonWrapper.cs(53,75): error CS0433: The type 'IOrderedDictionary' exists in both 'System.Collections.Specialized, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'WinRTLegacy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

    This is on 5.2.1p1 AND 5.2.1p2.
     
  37. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Somehow we missed this type, we'll remove it from WinRTLegacy in upcoming patch release, in the mean time, try unzipping this WinRTLegacy, and place them in <5.2.1p2 installation path>\Editor\Data\PlaybackEngines\metrosupport\Managed\UAP and see if the works. (Backup previous WinRTLegacy.dll and WinRTLegacy.pri) and see if that works.
     

    Attached Files:

  38. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    Ok great, thanks!

    A related issue that seems to not involve WinRTLegacy:

    Assets\Shared\InControl\Source\Utility\Utility.cs(244,4): error CS0433: The type 'StorageFolder' exists in both 'Windows.Foundation.UniversalApiContract, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' and 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'

    This and a few other classes (StorageFile, FileIO, and CreationCollisionOption) are keeping me from compiling to Windows 10 Universal right now (These are all in the InControl Asset Store plugin so I imagine it could affect quite a few people). Looks like its conflicted between Windows and Windows.Foundation.UniversalApiContract? Any thoughts/fixes for this?
     
  39. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,920
    Try 5.2.1p2
     
  40. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    Ah, right! Sorry, I forgot I reverted back after it didn't fix the first problem. XP