2

I'm having a strange error with Umbraco/uCommerce, I built a support library and suddenly I'm getting a strange error preventing compilation.

Error 9 The call is ambiguous between the following methods or properties: 'uCommerce_Boilerplate.Web.Controllers.ExtensionFunctions.ToDescription(System.Enum)' and 'uCommerce_Boilerplate.Web.Controllers.ExtensionFunctions.ToDescription(System.Enum)'

I have one file that contains several features, and this is the snippet prompting the error.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using UCommerce;
using UCommerce.EntitiesV2;
using UCommerce.Infrastructure;
using UCommerce.Transactions;
using UCommerce.Transactions.Payments;
using UCommerce.Transactions.Payments.Dibs;

namespace uCommerce_Boilerplate.Web.Controllers
{
    public static class ExtensionFunctions
    {
        public static string ToDescription(this Enum value)
        {
            var da = (DescriptionAttribute[])(value.GetType().GetField(value.ToString())).GetCustomAttributes(typeof(DescriptionAttribute), false);
            return da.Length > 0 ? da[0].Description : value.ToString();
        }
    }
    public static class SupportLib
    {
        public enum MethodName
        {
            [Description("Invoice")] Invoice = 1,
        }
        public static void RunOrder(MethodName methodName = MethodName.Invoice)
        {
            // The methodName.ToDescription() is throwing the error
            PaymentMethod method = getPaymentMethod(methodName.ToDescription());
        }
    }
}
Thomas Andreè Wang
  • 3,379
  • 6
  • 37
  • 53
  • Where is this method stored? In it's own assembly? – toadflakz Mar 09 '15 at 09:28
  • I hit enter errorously posting the question alittle early. I have one file called SupportLib.cs located in the Controllers folder, and it contains both parts of code, it also contains other support classes that don't throw errors. – Thomas Andreè Wang Mar 09 '15 at 09:31
  • Does your assembly contain `UserControl` classes that you've dragged from the VS Toolbox onto a Designer surface? – toadflakz Mar 09 '15 at 09:36
  • maybe, how would that play a role? im only setting up the class on the backend, the code is not used by anything yet – Thomas Andreè Wang Mar 09 '15 at 09:37
  • The Designer automatically adds a reference to the current assembly whenever a UserControl is dragged onto a surface. Your assembly is depending on itself. – toadflakz Mar 09 '15 at 09:43
  • Hmm, well this is a razor MVC thing so you cant really drag anything to a designer. I just noticed the error really only pops up after a successful compile. meaning that I can move `ExtensionFunctions` out to a different file compile once and then errors move back compile once and then errors – Thomas Andreè Wang Mar 09 '15 at 09:49

1 Answers1

3

You may have a circular reference in your assembly references which is why the method call is suddenly ambiguous.

As you described in the question comments you have used UserControls from that assembly within itself, the VS Designer might have added a reference of the UserControl's containing assembly to itself as this is what sometimes happens when you use a UserControl from the VS Toolbox.

toadflakz
  • 7,764
  • 1
  • 27
  • 40
  • yes its definitely a circular issue, the class is just standing there and generating 7 errors on on error somehow. The class and its function is not used by anything other than how its shown in the code. – Thomas Andreè Wang Mar 09 '15 at 10:08
  • If i move the function into the SupportLib and delete the ExtensionFunctions class, the error is stil there referencing the the now non existant ExtensionFunctions and SupportLib. – Thomas Andreè Wang Mar 09 '15 at 10:12