Build error that wasn't there before

Apr 10 2023 8:02 PM

I have a very large ASP.NET application. Recently we decided to migrate from local hosting to Azure.

However, I am getting compiler errors that I'm not getting locally.

/// <summary>
/// Returns either <paramref name="potentiallyNullValue"/> or the minimum value allowed by its <paramref name="type"/> if it's null.
/// </summary>
/// <param name="potentiallyNullValue"></param>
/// <param name="type"></param>
/// <returns></returns>
[Pure]
public static object GetValueOrFloor(this object potentiallyNullValue, Type type)
{
    if(type is null)
    {
        throw new ArgumentNullException("type", "The supplied type must exist (ie cannot be null, which it is in this case).");
    }
    else if(potentiallyNullValue != null && !type.Equals(potentiallyNullValue.GetType()))
    {
        throw new ArgumentException("The supplied type must match the type of object this method was called upon.");
    }

    if(type.Equals(typeof(DateTime)) || type.Equals(typeof(DateTime?)))
    {
        return potentiallyNullValue ?? DateTime.MinValue;
    }
    else if(type.Equals(typeof(int)) || type.Equals(typeof(int?)))
    {
        return potentiallyNullValue ?? int.MinValue;
    }
    else if(type.Equals(typeof(uint)) || type.Equals(typeof(uint?)))
    {
        return potentiallyNullValue ?? uint.MinValue;
    }
    else if(type.Equals(typeof(short)) || type.Equals(typeof(short?)))
    {
        return potentiallyNullValue ?? short.MinValue;
    }
    else if(type.Equals(typeof(ushort)) || type.Equals(typeof(ushort?)))
    {
        return potentiallyNullValue ?? ushort.MinValue;
    }
    else if(type.Equals(typeof(long)) || type.Equals(typeof(long?)))
    {
        return potentiallyNullValue ?? ushort.MinValue;
    }
    else if(type.Equals(typeof(ulong)) || type.Equals(typeof(ulong?)))
    {
        return potentiallyNullValue ?? ulong.MinValue;
    }
    else if(type.Equals(typeof(sbyte)) || type.Equals(typeof(sbyte?)))
    {
        return potentiallyNullValue ?? sbyte.MinValue;
    }
    else if(type.Equals(typeof(byte)) || type.Equals(typeof(byte?)))
    {
        return potentiallyNullValue ?? byte.MinValue;
    }
    else if(type.Equals(typeof(float)) || type.Equals(typeof(float?)))
    {
        return potentiallyNullValue ?? float.MinValue;
    }
    else if(type.Equals(typeof(double)) || type.Equals(typeof(double?)))
    {
        return potentiallyNullValue ?? double.MinValue;
    }
    else if(type.Equals(typeof(decimal)) || type.Equals(typeof(decimal?)))
    {
        return potentiallyNullValue ?? decimal.MinValue;
    }
    else if(type.Equals(typeof(char)) || type.Equals(typeof(char?)))
    {
        return potentiallyNullValue ?? char.MinValue;
    }
    else if(type.Equals(typeof(string)))
    {
        return string.IsNullOrWhiteSpace((string)potentiallyNullValue) ? string.Empty : potentiallyNullValue;
    }
    else
    {
        throw new ArgumentException("Type is not one with a recongnized minimum value.");
    }
}

Specifically, the first if statement on line 10 gets error CS1031, "Type expected, A type parameter is expected."

This error does not occur locally, only when I try to deploy on Azure (which is set to ASP.NET 4.8). What is going on? What needs to change in the code to fix this? Is Azure using a different version of C#?


Answers (4)