System.Attribute errors when compiling for Windows Store / Phone 8.1 (130962)

I use a Singleton that will load a Prefab (from Resources) if the singleton instance isn’t found. Its a modified version of what can be found here:
http://kleber-swf.com/singleton-monobehaviour-unity-projects/

This seems to work fine for most builds (tested on iOS and Standalone Windows builds)

However, when trying to create a Windows Phone 8.1 Visual Studio Project (or Windows Universal 8.1), Unity reports the following errors that keep it from building the project (the code that generates the error is listed above)

if (System.Attribute.IsDefined (myType, typeof(SingletonPrefabAttribute)))
{
...
}

error CS0117: ‘System.Attribute’ does not contain a definition for ‘IsDefined’

SingletonPrefabAttribute attr = (SingletonPrefabAttribute) System.Attribute.GetCustomAttribute (myType, typeof(SingletonPrefabAttribute));

error CS0117: ‘System.Attribute’ does not contain a definition for ‘GetCustomAttribute’

Any ideas as to what could be causing this?

Note that this only occurs when compiling when building against the Microsoft C# compiler. It works as expected when building with Mono.

Same problem here. Not sure there's any option when building to HoloLens

1 Answer

1

I got around this by surrounding the code with

#if UNIYT_EDITOR
… Attribute.notgonnawork
#endif

You mean UNITY_EDITOR of course