-1

I am using MailChimp Library by brandonseydel, i am not able to create the 'MailChimpManager' object,getting the error a field initializer cannot reference non static field,method,property

 public string MailChimpAPIKey {
        get
        {
            using (BEntities entity=new BEntities())
            {
                var key = entity.tbl_Client_MailChimp_Settings.Where(p => p.CIN == CINNo).FirstOrDefault();
                if (key != null)
                    return key.APIKey;
                else
                    return "";
            }
        }
    }

    private static MailChimpManager Manager = new MailChimpManager(MailChimpAPIKey);
PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35
user9287106
  • 141
  • 3
  • 13
  • Error speaks for itself. You are trying to access non static object in your static method. Remove static or make MailChimpAPIKey static. – Incredible Jan 30 '18 at 06:05

2 Answers2

0

You are trying to use non-static filed with static class. Make your MailChimpAPIKey static and it will work. Also try to implement setter for MailChimpAPIKey.

Gaurang Dave
  • 3,956
  • 2
  • 15
  • 34
0

MailChimpAPIKey must be also static, or implement of IMailChimpManager must be non static

private IMailChimpManager Manager = new MailChimpManager(MailChimpAPIKey);
phoniq
  • 228
  • 1
  • 5