WinRTLegacy conflicts

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):

 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.

#if NETFX_CORE
using IO = WinRTLegacy.System.IO;
#else
using IO = System.IO;
#endif

Any help would be appreciated!

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.

Thanks for the response! Do you know approximately when 5.2p1 will be coming out?

I am guessing it will be released Sep 21.

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

  1. 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.

I got same error previously

 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:
error CS0234: The type or namespace name 'Full' does not exist in the namespace 'WinRTLegacyTMP' (are you missing an assembly reference?)

Any solutions?

You do not need to write “Full” in the namespace :slight_smile: 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.

Thanks for the quick response :slight_smile:
But now the old error popped back and got new error:

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 

The following assembly referenced from C:\YYY\Assets\Plugins\WSA\WinRTLegacy.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:\YYY\Assets\Plugins\WSA\).

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:\YYY\Assets\Plugins\WSA\WinRTLegacy.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
Can't find custom attr constructor image: C:\YYY\Assets\Plugins\WSA\WinRTLegacy.dll mtoken:

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.

Yes, thanks, that caused that Unhandled Exception error, but the original error unfortunately appears anyway :confused:

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'

Guess, I should wait for 5.2p1

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.

#if NETFX_CORE
extern alias WinRTLegacyTMP;
#endif
   
using UnityEngine;
using System.Collections;

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

public class AssetStreamer : MonoBehaviour {

    private void Start (){
        string path = Application.dataPath + "/StreamingAssets";
    }

    public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
    public string result = "";

    IEnumerator Example() {
        if(filePath.Contains("://")) {
       
            WWW www = new WWW(filePath);
            yield return www;
            result = www.text;
        }
        else
            result = System.IO.File.ReadAllText(filePath);
    }
}

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

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);).

Awesome, that worked. Thanks! :slight_smile:
btw I wish luck to Lithuania for tommorows game vs Serbia :wink:

Hehe, thanks! :slight_smile: Also, great that it finally worked for you.

Shouldn’t this bug be fixed in 5.2p1? I just installed the patch release and the bug still exists.

Sadly that fix missed 5.2.0p1, it should be in 5.2.1p1 which should be released in Sep 23.

Sorry for inconvience

I am also having this issue. I can’t seem to get the work around to work. :frowning:

Is there any way to just remove WINRT legacy? I can rewrite these classes myself I guess.

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 :slight_smile: No promises, that it’ll work though