danesparza / MailChimp.NET

:envelope: .NET Wrapper for the MailChimp v2.0 API
MIT License
179 stars 119 forks source link

Issue with System.IO.FileNotFoundException: Filen eller assemblyen 'ServiceStack.Text, Version=3.9.71.0 #100

Open bjarnef opened 10 years ago

bjarnef commented 10 years ago

I am using Umbraco /base and have installed MailChimp.NET 1.1.34 from NuGet. But when I call the url (which would be like this: http://www.mydomain.com/base/MailchimpNewsletter/SubscribeMail/{email}.aspx through a clean Umbraco install it returns something like this:

<error><![CDATA[MESSAGE:
Destinationen for en aktivering udløste en undtagelse.

STACKTRACE:
   ved System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   ved System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   ved System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   ved Umbraco.Web.BaseRest.RestExtensionMethodInfo.Invoke(String[] parameters)

INNEREXCEPTION:
System.IO.FileNotFoundException: Filen eller assemblyen 'ServiceStack.Text, Version=3.9.71.0, Culture=neutral, PublicKeyToken=null' eller en af dens afhængigheder kunne ikke indlæses. Den angivne fil blev ikke fundet.
Filnavn: 'ServiceStack.Text, Version=3.9.71.0, Culture=neutral, PublicKeyToken=null'
   ved MailChimp.MailChimpManager..ctor()
   ved MailChimp.MailChimpManager..ctor(String apiKey)
   ved UmbracoAjaxSubscribeForm.Library.MailchimpSubscription.SubscribeMail(String email) i c:\Users\Bjarne\Documents\Visual Studio 2013\Projects\MailChimp.NET_example\MailChimp.NET_example\Library\MailchimpSubscription.cs:linje 38

WRN: Logføring af assemblybinding er deaktiveret.
Logføring af assemblybindingsfejl aktiveres ved at angive registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) til 1.
Bemærk! Ydeevnen forringes ved logføring af assemblybindingsfejl.
Denne funktion deaktiveres ved at fjerne registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog].
]]></error>

Maybe it's something related or simular to this issue: https://github.com/danesparza/MailChimp.NET/issues/48

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Web.Script.Serialization;
using Umbraco.Web.BaseRest;
using MailChimp;
using MailChimp.Helper;
using MailChimp.Lists;
using Newtonsoft.Json;
//using ServiceStack.Text;

namespace UmbracoAjaxSubscribeForm.Library
{
    [RestExtension("MailchimpNewsletter")]
    public class MailchimpSubscription
    {
        private enum status { SUCCESS, ERROR };
        private static string api_key = System.Web.Configuration.WebConfigurationManager.AppSettings["MailChimp:apiKey"];
        private static string list_key = System.Web.Configuration.WebConfigurationManager.AppSettings["MailChimp:listKey"];

        [RestExtensionMethod(ReturnXml = false, AllowAll = true)]
        public static string SubscribeMail(string email)
        {
            if (!string.IsNullOrEmpty(email) && checkEmail(email))
            {
                MailChimpManager mc = new MailChimpManager(api_key);
                ListResult lists = mc.GetLists();
                string listId = list_key; //lists.Data[0].Id;

                //  Create the email parameter
                EmailParameter emailParam = new EmailParameter()
                {
                    Email = email
                };

                //  Check if the email already exists
                Matches match = mc.SearchMembers(emailParam.Email, list_key); //lists.Data[0].Id
                EmailParameter ep = new EmailParameter();

                MailChimpResponse response = new MailChimpResponse();

                if (match.ExactMatches.Members.Count > 0)
                {
                    // already subscribed       
                    ep.Email = emailParam.Email;
                    response.emailExists = true;
                    //Response.Write("You are already subscribed");
                }
                else
                {
                    // subscribe
                    ep = mc.Subscribe(listId, emailParam, null, "html", false, false, true, false);
                    response.emailExists = false;
                    //Response.Write("You are now subscribed");
                }
                response.emailParameter = ep;
                return JsonConvert.SerializeObject(response);
            }
            else
            {
                return "";
            }
        }

        private static bool checkEmail(string email)
        {
            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            System.Text.RegularExpressions.Match match = regex.Match(email);
            return match.Success;
        }

        public class MailChimpResponse
        {
            public EmailParameter emailParameter { get; set; }
            public bool emailExists { get; set; }
        }
    }
}

but if I then include using ServiceStack.Text; and rebuild the project, copy the compiled assembly + the compiled ServiceStack.Text.dll to my Umbraco installation, then it just fine return the exspected json like this:

{
emailParameter: {
    email: "myemail1@mail.com",
    euid: "xxxxxxxxxxxx",
    leid: "xxxxxxxxxxxx"
},
emailExists: false
}

where xxxxxxxxxxxx of course is the right id's ... or if the email already exists in the list:

{
emailParameter: {
    email: "myemail2@mail.com",
    euid: null,
    leid: null
},
emailExists: true
}

as I get an exception when calling the Subscribe method when email already exists in the list https://github.com/danesparza/MailChimp.NET/issues/99, I just create a new instanse of EmalParameter and set the email + adding a bool with value true.

Is the issue with ServiceStack.Text an issue with the NuGet package? It shouldn't be necessary to include that reference?

danesparza commented 10 years ago

The MailChimp.NET library has a NuGet package dependency on ServiceStack.Text -- it should get installed automatically when you install MailChimp.NET through NuGet.

danesparza commented 10 years ago

If you look at the NuGet page, you can see that NuGet successfully detects the dependency on ServiceStack.Text. If you install using the package manager console, you should get output that describes the install process -- did it fail to download ServiceStack.Text at that time?

bjarnef commented 10 years ago

I didn't notice if ServiceStack.Text was installed first time... the NuGet package was succesfully installed, but the ServiceStack.Text assembly was missing.. and wasn't build with my project, when only including reference to MailChimp.dll ... at first I didn't notice ServiceStack.Text was missing, perhaps because I had the project and Umbraco both in Visual Studio, but when I moved the compiled dll and usercontrol to another website in WebMatrix I got the error..

Should the developers include using ServiceStack.Text too? It doens't seem to be enough with:

using MailChimp;
using MailChimp.Helper;
using MailChimp.Lists;

I also have to include ServiceStack.Text is my project to build the ServiceStack.Text.dll.

bjarnef commented 10 years ago

I tried to install the NuGet package in a clean install:

PM> Install-Package MailChimp.NET
Attempting to resolve dependency 'ServiceStack.Text (= 3.9.71)'.
Installing 'ServiceStack.Text 3.9.71'.
Successfully installed 'ServiceStack.Text 3.9.71'.
Installing 'MailChimp.NET 1.1.34.0'.
Successfully installed 'MailChimp.NET 1.1.34.0'.
Adding 'ServiceStack.Text 3.9.71' to TestMailChimpNET.
Successfully added 'ServiceStack.Text 3.9.71' to TestMailChimpNET.
Adding 'MailChimp.NET 1.1.34.0' to TestMailChimpNET.
Successfully added 'MailChimp.NET 1.1.34.0' to TestMailChimpNET.

when I build the project these assemblies are generated: MailChimp.dll, ServiceStack.Text.dll and TestMailChimpNET.dll (my project assembly)

jphellemons commented 9 years ago

It would be better if the MailChimp.Net nuget would depend on a minimum version of service stack.

SteveVaneeckhout commented 9 years ago

Mailchimp.net uses is the latest free 3.x version. Newer versions are not free anymore.

jphellemons commented 9 years ago

Is it an option to move away from ServiceStack and move to the json.net of newton-king http://james.newtonking.com/json

mdissel commented 9 years ago

It's not only the json part that's being used, also the REST features from ServiceStack.

jphellemons commented 9 years ago

Thank you mdissel! that is a valid point. I started a fork to see how much work it would be to move away from servicestack https://github.com/jphellemons/MailChimp.NET it is not compiling yet, because of the jsconfig work in the mergevar method

theofanis commented 8 years ago

Please see #176 for an attempt to drop ServiceStack dependency