anderly / dnsimple-csharp

A C# wrapper for the DNSimple REST API
Apache License 2.0
17 stars 10 forks source link

Error Creating Domain - user issue, code issue, library issue or api issue? #7

Closed drewid closed 9 years ago

drewid commented 9 years ago

I am a newbie to this library and DnSimple.

Did the API change or is there an error that is not yet raised?

I am running a pretty basic test via Postman and am getting the following error from the following code. I get the error both authenticating with password or token and also with either version of JxonFx (the original - 2.0.1106.2610) or the new one (2.0.1298.2802).

Code: var dns = new DNSimpleRestClient("name@mydomain.com", null", "SomeTokenHere); dynamic result = dns.AddDomain(domain);

Error Returned: { "message": "An error has occurred.", "exceptionMessage": "Method 'Deserialize' in type 'DNSimple.Infrastructure.JsonFxDeserializer' from assembly 'DNSimple.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.", "exceptionType": "System.TypeLoadException", "stackTrace": " at DNSimple.DNSimpleRestClient..ctor(String username, String password, String token)\r\n at xyz.DomainsController.CreateDomain(String domain) in path\to\controller\DommainsController.cs:line 95\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>cDisplayClass10.b9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }

Strangely enough I think I am also getting an error submitting directly to the site but am not sure if I am just doing something wrong. Using postman:

POST /v1/domains HTTP/1.1 Host: api.dnsimple.com X-DNSimple-Token: name@mydomain.com:SomeTokenHere Cache-Control: no-cache { "domain": { "name": "example.com" } }

400 message being returned: { "message": "Required parameter missing: domain" } { "message": "Required parameter missing: domain" }

drewid commented 9 years ago

Still can't figure out why the simple library call is failing. My project builds and includes the dependent packages.

Never mind the second part about the direct API submittal. I was missing the Accept and Content-Type headers. When I submitted them as follows it submitted fine.

POST /v1/domains HTTP/1.1 Host: api.dnsimple.com X-DNSimple-Token: name@mydomain.com:SomeTokenHere Accept: application/json Content-Type: application/json Cache-Control: no-cache

anderly commented 9 years ago

I just created a new c# console app and Installed the DNSimple package from NuGet and added a domain and was unable to reproduce the problem.

What version of the package are you using?

drewid commented 9 years ago

Current version, c# webapi project, target is 4.5.

Failure both with default version of JxonFx (the original - 2.0.1106.2610) or the new one (2.0.1298.2802).

Thanks!

anderly commented 9 years ago

Can you try it in a console app and see if it works there?

This is what is working for me:

var dns = new DNSimpleRestClient("user@example.com", token: "api_token_here");
dynamic result = dns.AddDomain("example.com");
Console.WriteLine(result.domain.name);
anderly commented 9 years ago

Also, I'm working on an updated version that uses async and removes the dependency on JsonFx and RestSharp. Interface will change a bit, but same overall functionality. Will support .NET 4.5 and up only. Current one will remain for backward compatibility for .NET 2.0-4.0 clients. Don't have an ETA on it yet though.

anderly commented 9 years ago

I just published an updated version 0.5.1 on NuGet that removes the JsonFx dependency. It also removes the assemblies for JsonFx and RestSharp from being included in the package and let's NuGet manage the dependencies. Now, it is using Json.NET for deserialization. Please update to 0.5.1 and let me know if you still have any issues.

drewid commented 9 years ago

Thanks! Will check right away.

drewid commented 9 years ago

hmm - the update seemed to blow away restsharp from the package - am readding it.

anderly commented 9 years ago

NuGet should restore it since it's a dependency.

anderly commented 9 years ago

Just updated the package again 0.5.2. Please try that version. I updated the RestSharp dependency.

drewid commented 9 years ago

I had to redo/rebuild my packages - ended up ok

anderly commented 9 years ago

Just tested it with a WebApi project on .NET 4.5.1. You may need to add an assembly binding redirect in your web.config for Json.NET as follows:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
drewid commented 9 years ago

Things are all set! After removing and re-adding my packages things are now fine, with the proper references to json.net and restsharp.

Thanks!

anderly commented 9 years ago

Great!