Not allowed reference System Library (assembly) in builds for Windows ? and WinRTLegacy usage issue

This was quite a shock.

It seems that there are several .NET types missing on the Windows App Store scripting back end .
Unity added some of its own.

If you have some any kind of Class library project which exports a managed library which you use in unity and is allows to be included in build then you will get this error. (Post build error for me )
Expand to view error message
[spoiler]
**

[quote]**
Reference Rewriter found some errors while running with command --target=“Temp\StagingArea\MyLibrary.dll” --additionalreferences=“Temp\StagingArea” --platform=“C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd” --support=“Temp\StagingArea\WinRTLegacy.dll” --supportpartialns=Unity.Partial --system=System --dbg=pdb --framework=“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5.1” --alt=System.Xml.Serialization --ignore=System.IConvertible,mscorlib.
Error: method System.Reflection.Assembly System.Type::get_Assembly() doesn’t exist in target framework. It is referenced from MyLibrary.dll at System.Resources.ResourceManager MyLibrary.Properties.InternalResources::get_ResourceManager().
Error: method System.Object System.Resources.ResourceManager::GetObject(System.String,System.Globalization.CultureInfo) doesn’t exist in target framework. It is referenced from MyLibrary.dll at UnityEngine.Texture2D MyLibrary.Properties.InternalResources::get_Image1().
UnityEngine.Debug:LogError(Object)
PostProcessWinRT:RunReferenceRewriter() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:579)
PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:123)
UnityEditor.HostView:OnGUI()
**[/quote]
**
[/spoiler]

Now, I know that this is stating that the build encountered an error due to the fact that the Windows Store back end does not include support for System ??.
instead we we have to use the WinRTLegacy library
like this

#if NETFX_CORE
using AssemblyTitle = WinRTLegacy.System.Reflection.AssemblyTitleAttribute;
using AssemblyDescription = WinRTLegacy.System.Reflection.AssemblyDescriptionAttribute;
using AssemblyConfiguration = WinRTLegacy.System.Reflection.AssemblyConfigurationAttribute;
using AssemblyCompany = WinRTLegacy.System.Reflection.AssemblyCompanyAttribute;
using AssemblyProduct = WinRTLegacy.System.Reflection.AssemblyProductAttribute;
using AssemblyCopyright = WinRTLegacy.System.Reflection.AssemblyCopyrightAttribute;
using AssemblyTrademark = WinRTLegacy.System.Reflection.AssemblyTrademarkAttribute;
using AssemblyCulture = WinRTLegacy.System.Reflection.AssemblyCultureAttribute;
using AssemblyVersion = WinRTLegacy.System.Reflection.AssemblyVersionAttribute;
using AssemblyFileVersion = WinRTLegacy.System.Reflection.AssemblyFileVersionAttribute;
#else
using AssemblyTitle = System.Reflection.AssemblyTitleAttribute;
using AssemblyDescription = System.Reflection.AssemblyDescriptionAttribute;
using AssemblyConfiguration = System.Reflection.AssemblyConfigurationAttribute;
using AssemblyCompany = System.Reflection.AssemblyCompanyAttribute;
using AssemblyProduct = System.Reflection.AssemblyProductAttribute;
using AssemblyCopyright = System.Reflection.AssemblyCopyrightAttribute;
using AssemblyTrademark = System.Reflection.AssemblyTrademarkAttribute;
using AssemblyCulture = System.Reflection.AssemblyCultureAttribute;
using AssemblyVersion = System.Reflection.AssemblyVersionAttribute;
using AssemblyFileVersion = System.Reflection.AssemblyFileVersionAttribute;
#endif

I still get post build errors and I am not able to test the actual build. So I assume the usage example above is nonsense.

Furthermore , even using Lists is an issue, as we must use System.Colletions.Generic.

but using

#if NETFX_CORE
using List = WinRTLegacy.System.Colletions.Generic.List
#else
using List = System.Colletions.Generic.List // error
#endif

is no good

I assume then that any developer using a 3rd party library which uses System or any other unsupported Windows Store assembly will get build errors ?

Then would a workaround be to add those libraries to the Plugins folder of the project and include them in the build ?

You shouldn’t have to explicitly use anything from WinRTLegacy… Furthermore, afaik List works just fine on Windows Store without doing anything. Is “ResourceManager” the only thing that it is complaining about?

good to know that.
The only Library my assembly uses except for UnityEngine is System.

Not only ResourceManager, which is “System.Resources.ResourceManager”
but with the usage o anything derived from the System assembly.

like
System.Reflection
System.Collections.Generic
System.Linq
etc…

I see error messages like these in the console . Each pointing to a different location where Aderrived method or otherwise of System is used.

^ That is only one of the places where it finds an error but all in all the errors are basically the same.

It would be fine if i could use something like this

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

bit any method derived from Linq will still be redlined as having an error.

or should that just be

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

That’s not how it works… types in WinRTLegacy.dll are in the same system namespace so you don’t have to change your code. Still, some types are not available even in WinRTLegacy (we did not make replacements for everything).

Anyway, did you try giving IL2CPP a shot? It has the same API surface as any other Unity platform, so you shouldn’t get any missing types errors if your game works say on the standalone player.

:hushed: really, that would be great !

is that IL2CPP at “Scripting Backend” under “Configuration” in Player Settings ?

If so , then i am getting this warning message in by build settings window “Currently selected scripting backend (IL2CPP) does not support the selected SDK, I am on WIndows 8.1 , 64bit. Is this a limitation by OS or do i not have the right sdk”

Also , I found out something interesting.

Only when resources are added to the DLL and and attempt to build so i get the errors.

you can download the small example class library project here (i think checking out the project would be easier)
OR
see the automatically generated code for the Resources here

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Listing.Properties {
    using UnityEngine;
   
   
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class ImageResources {
       
        private static global::System.Resources.ResourceManager resourceMan;
       
        private static global::System.Globalization.CultureInfo resourceCulture;
       
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal ImageResources() {
        }
       
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Listing.Properties.ImageResources", typeof(ImageResources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
       
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
       
        /// <summary>
        ///   Looks up a localized resource of type Texture2D.
        /// </summary>
        internal static Texture2D Image1 {
            get {
                object obj = ResourceManager.GetObject("Image1", resourceCulture);
                return ((Texture2D)(obj));
            }
        }
    }
}

Yeah, IL2CPP is only supported when targeting Windows 10 SDK. There’s little use of targeting Windows 8.1, though, since the market share is low and is continuing to drop fast.

What can I do to mitigate this issue ?

I modified the auto-generated code with the following. However I still get build errors .

All errors are listed under the code. Is this my problem ? i’m not sure of how to fix it .

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Listing.Properties {
    using UnityEngine;

#if NETFX_CORE
    using System = WinRTLegacy.System;
    using GeneratedCodeAttribute = WinRTLegacy.System.CodeDom.Compiler.GeneratedCodeAttribute;
    using DebuggerNonUserCodeAttribute = WinRTLegacy.System.Diagnostics.DebuggerNonUserCodeAttribute;
    using CompilerGeneratedAttribute = WinRTLegacy.System.Runtime.CompilerServices.CompilerGeneratedAttribute;
    using ResourceManager = WinRTLegacy.System.Resources.ResourceManager;
    using CultureInfo = WinRTLegacy.System.Globalization.CultureInfo;
    using SuppressMessageAttribute = WinRTLegacy.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
    using EditorBrowsableAttribute = WinRTLegacy.System.ComponentModel.EditorBrowsableAttribute;
    using EditorBrowsableState = WinRTLegacy.System.ComponentModel.EditorBrowsableState;
#else
    using System =  System;
    using GeneratedCodeAttribute =  System.CodeDom.Compiler.GeneratedCodeAttribute;
    using DebuggerNonUserCodeAttribute =  System.Diagnostics.DebuggerNonUserCodeAttribute;
    using CompilerGeneratedAttribute =  System.Runtime.CompilerServices.CompilerGeneratedAttribute;
    using ResourceManager =  System.Resources.ResourceManager;
    using CultureInfo =  System.Globalization.CultureInfo;
    using SuppressMessageAttribute =  System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
    using EditorBrowsableAttribute =  System.ComponentModel.EditorBrowsableAttribute;
    using EditorBrowsableState =  System.ComponentModel.EditorBrowsableState;
#endif

    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [DebuggerNonUserCodeAttribute()]
    [CompilerGeneratedAttribute()]
    internal class ImageResources {
       
        private static  ResourceManager resourceMan;
       
        private static  CultureInfo resourceCulture;
       
        [ SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal ImageResources() {
        }
       
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [ EditorBrowsableAttribute( EditorBrowsableState.Advanced)]
        internal static  ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                     ResourceManager temp = new  ResourceManager("Listing.Properties.ImageResources", typeof(ImageResources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
       
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [ EditorBrowsableAttribute( EditorBrowsableState.Advanced)]
        internal static  CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
       
        /// <summary>
        ///   Looks up a localized resource of type Texture2D.
        /// </summary>
        internal static Texture2D Image1 {
            get {
                object obj = ResourceManager.GetObject("Image1", resourceCulture);
                return ((Texture2D)(obj));
            }
        }
    }
}

Post Build Errors

Where have you pulled the idea of using stuff from WinRTLegacy like that?
There are only few types in WinRTLegacy namespace, only because some classes do exist in .NET for Windows Store, but they are missing some methods, so we added replacement classes to WinRTLegacy, that do have those methods.
In short, DO NOT use WinRTLegacy namespace unless it is the types listed in this page:
https://docs.unity3d.com/Manual/windowsstore-missingtypes.html

Then there is no way for libraries with resource files to be built for a Windows Store project then ?

then there is a 100% chance of getting build errors.

If I dont need to use WinRTLegacy then i don’t know why it doesnt work.

When reference rewriter complains about missing types or methods, that already means that they aren’t in neither system assemblies, nor WinRTLegacy (Reference rewriter knows how to check WinRTLegacy.dll automatically). That means that you either have to stop using those types, implement them yourself or don’t use .NET scripting backend (and switch to IL2CPP instead).

Btw, why are you so keen on targeting Windows 8.1?

I see, I am using windows 8.1 and cant target Windows 10 so I cant use IL2CPP.

This i a huge problem for anyone using a 3rd party dll.
and an even bigger problem if that library uses resources.
This is really really bad :frowning: rally really really bad

I had to dump my resource
I may even need to make a custom resource reader