Type or namespace name 'Description' could not be found

Viewed 1344

Im currently working on a MR application for UWP. I'm building the application in unity3d (tested in 5.5.2 and 2017.1.2) and everything works fine when i press play within unity, no compile errors what so ever... But when I go to build the application i get errors Assets\Script\DMEWebRequest.cs(35,10): error CS0246: The type or namespace name 'DescriptionAttribute' could not be found (are you missing a using directive or an assembly reference?) and Assets\Script\DMEWebRequest.cs(35,10): error CS0246: The type or namespace name 'Description' could not be found (are you missing a using directive or an assembly reference?)

To my knowledge the DescriptionAttribute is a part of System.ComponentModel

Code snippets from my C# script

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;


//Makes a dropdown menu in the inspector
public enum EGU {
    [Description("")] None,
    [Description("ºC")] DegreesCelcius,
    [Description("kW")] KiloWatts,
    [Description("kW/h")] KiloWattsPerHour,
    [Description("MW")] MegaWatts,
    [Description("MW/h")] MegaWattsPerHour,
    [Description("M³")] CubicMeters,
    [Description("M³/h")] CubicMetersPerHour,
    [Description("%")] Procentage,
    [Description("º")] Degrees,
    [Description("l/s")] LiterPerSecond,
    [Description("cm")] CentiMeters,
    [Description("m")] Meters,
    [Description("mg/l")] MiliGramPerLiter,
    [Description("g/l")] GramPerLiter
    }

Hope someone can help me figure out what directive or reference I'm missing.

/T

2 Answers

Your code should work fine when building for PC, Mac & and Linux Standalone. It should not work when you switch the platform to Universal Windows Platform because System.ComponentModel.Description uses DescriptionAttribute which is not supported on UWP. UWP removed support for many .NET API. That's one thing you should bear in mind when making UWP app.

It works with IL2CPP as scripting backend. If you need the deprecated .NET scripting backend from Unity 2018 LTS (removed in 2019) you can try to add DescriptionAttribute.cs from Mono or decompiled code as @Programmer suggested. It might work in some situation but in my case I ran into more errors.

Finally I gave up when I tried to make ARSubsystem package compiling for UWP (.NET) which was needed in iOS/Android builds of the same project. Instead I manipulated package manifest to exclude / include the packages depending on the platform. There are a couple of ways to accomplish that like InitializeOnLoad attribute or IPreprocessBuildWithReport interface.

Related