daveaglick / NetlifySharp

A .NET API Client for Netlify
http://netlifysharp.netlify.com/
MIT License
16 stars 6 forks source link

Exception when pushing to Netlify #3

Closed mfkl closed 5 years ago

mfkl commented 5 years ago

Hello,

Opening this on GitHub as you said on Gitter.

The stack I get is

NetlifySharp.Models.Model..ctor(NetlifyClient client)
   at lambda_method(Closure , Object[] )
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
   at NetlifySharp.Operations.Operation`1.ReadJsonResponseAsync[TModel](HttpResponseMessage response)
   at NetlifySharp.Operations.ResponseOperation`2.ReadResponseAsync[TResponse](HttpResponseMessage response)
   at NetlifySharp.Operations.Operation`1.GetResponseAsync[TResponse](CancellationToken cancellationToken)
   at NetlifySharp.Operations.ResponseOperation`2.SendAsync(CancellationToken cancellationToken)
   at Submission#0.<<<Initialize>>b__0_3>d.MoveNext()
message with Value cannot be null.
Parameter name: client

My cake script looks just like yours

var netlifyToken = EnvironmentVariable(mywebsite_NETLIFY_TOKEN");
var client = new NetlifyClient(netlifyToken);
await client.UpdateSite("mywebsite.netlify.com", MakeAbsolute(outputDir).FullPath).SendAsync().Wait();

The weird part is that while this blows up on the CI, the website seems to still be updated. Current workaround is just to add a try/catch but it seems fishy ^^

daveaglick commented 5 years ago

Thanks - it looks like the result message being returned is failing to deserialize. That explains why the site is still published - if it's just the response that's not in the expected format than the site has already been pushed. My guess is that Netlify recently changed their JSON contract and NetlifySharp needs to adapt.

yansklyarenko commented 5 years ago

@mfkl Strange, I've just tried to reproduce it but failed. Could it possibly be an incompatible version of Newtonsoft.JSON package? Perhaps, if you include it as #addin explicitly and Cake pulls incorrect version... Just a thought. Besides, the current version of Netlify open API was released back in April, so it's unlikely to be a changed JSON contract, right?

daveaglick commented 5 years ago

so it's unlikely to be a changed JSON contract, right?

Probably right. And you could be on to something with different versions of Newtonsoft. I'm going to be updating NetlifySharp soon(ish) for integration directly into Statiq so I'll probably up the version or switch to in-the-box JSON serialization.

Anyway, I'm glad you're back up and running. I'll close the issue but feel free to reopen or open a new one if it looks like it's breaking again.

daveaglick commented 5 years ago

Whops - just noticed the comment was from a different user! Thanks @yansklyarenko for trying to do a repro, I was also unable to reproduce so that checks out.

@mfkl Are you still getting failures? If so (and it wasn't something temporarily wrong with their API), I'll keep digging. Any indication a Newtonsoft version difference might be part of it as @yansklyarenko suggested?

mfkl commented 5 years ago

Hey,

Yep, still hitting this.

My CI looks like

dotnet tool install -g Cake.Tool
dotnet cake build.cake --target=Publish-Site

I don't use JSON yet in my Wyam script, just

#n Wyam.Yaml
#n Wyam.Markdown
#n Wyam.Razor

My config.wyam.packages.xml looks like this (and does contain a Newtonsoft reference)

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Wyam.Yaml" version="2.1.2" targetFramework="netcoreapp2.1">
    <package id="YamlDotNet" version="4.3.1" targetFramework="netcoreapp2.1" />
  </package>
  <package id="Wyam.Markdown" version="2.1.2" targetFramework="netcoreapp2.1">
    <package id="Markdig" version="0.15.4" targetFramework="netcoreapp2.1" />
  </package>
  <package id="Wyam.Razor" version="2.1.2" targetFramework="netcoreapp2.1">
    <package id="Microsoft.AspNetCore.Cryptography.Internal" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.DataProtection.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Diagnostics.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Razor.Language" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.CSharp" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.DiaSymReader.Native" version="1.7.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.DependencyInjection" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.FileSystemGlobbing" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Localization.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.ObjectPool" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Newtonsoft.Json" version="11.0.2" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.JsonPatch" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Newtonsoft.Json.Bson" version="1.0.1" targetFramework="netcoreapp2.1" />
    <package id="System.AppContext" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Buffers" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Collections" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Collections.Immutable" version="1.3.1" targetFramework="netcoreapp2.1" />
    <package id="System.ComponentModel.Annotations" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Console" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="netcoreapp2.1" />
    <package id="System.Diagnostics.FileVersionInfo" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Diagnostics.StackTrace" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Globalization" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.IO" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.IO.Compression" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.IO.FileSystem" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Linq" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Linq.Expressions" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="netcoreapp2.1" />
    <package id="System.Reflection" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Reflection.Metadata" version="1.4.2" targetFramework="netcoreapp2.1" />
    <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="netcoreapp2.1" />
    <package id="System.Memory" version="4.5.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Primitives" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Http.Features" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.ResponseCaching.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Caching.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Configuration.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.FileProviders.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.FileProviders.Composite" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.FileProviders.Physical" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Hosting.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Options" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Authorization" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Caching.Memory" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.Localization" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Net.Http.Headers" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.DotNet.PlatformAbstractions" version="2.1.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.DependencyModel" version="2.1.0" targetFramework="netcoreapp2.1" />
    <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.AccessControl" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Win32.Registry" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Permissions" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Security.Cryptography.Xml" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="System.Text.Encoding" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Text.Encoding.CodePages" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Html.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Http.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Authorization.Policy" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Hosting.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.DataProtection" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Http.Extensions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Razor" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Razor.Runtime" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Routing.Abstractions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.Abstractions" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Routing" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.WebUtilities" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Antiforgery" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Http" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Authentication.Core" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.Extensions.WebEncoders" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="System.Threading" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Threading.Tasks" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.Core" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.DataAnnotations" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.Formatters.Json" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.ViewFeatures" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="System.Threading.Tasks.Parallel" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Threading.Thread" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.ValueTuple" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Xml.XDocument" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Xml.XPath" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="System.Xml.XPath.XDocument" version="4.3.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.CodeAnalysis.Common" version="2.8.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.CodeAnalysis.CSharp" version="2.8.0" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.CodeAnalysis.Razor" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.Razor.Extensions" version="2.1.1" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.Razor" version="2.1.3" targetFramework="netcoreapp2.1" />
    <package id="Microsoft.AspNetCore.Mvc.RazorPages" version="2.1.3" targetFramework="netcoreapp2.1" />
  </package>
</packages>
yansklyarenko commented 5 years ago

@mfkl I still suspect there's something wrong with the versions being used.

When you install Cake like dotnet tool install -g Cake.Tool, it pulls down the latest Cake, which is 0.35.0 at the moment. On the other hand, Wyam was modified to target Cake 0.33.0 only in version 2.2.5. However, your packages.xml clearly indicates that you're using Wyam 2.1.2.

I have no idea where it goes wrong in your case, but I would try updating Wyam to something higher than 2.2.5 or pin the version of Cake to something older.

In my case, it's Cake v0.33.0 and Wyam v2.2.7, and it works just fine.

mfkl commented 5 years ago

Thanks for your help @yansklyarenko, I'll try this and report back tomorrow.

For the record, the reason I was installing it this way was because of https://github.com/Wyamio/Wyam/issues/858

daveaglick commented 5 years ago

Ugh. Yeah, that NuGet bug in Wyam has been a pain. Since the last comment on that issue there's been a couple more patch releases to try and resolve it once and for all - latest Wyam is now 2.2.9.

With regard to NetlifySharp I'm likely going to port it to the new System.Text.Json serialization soon if I can - that should eliminate any version clashes with Newtonsoft in Cake.

Looking forward, deployment is a core concept in Statiq. You'll be able to deploy a Statiq generated site to a number of static hosts (including Netlify) out of the box using the CLI. Something to look forward to :).

mfkl commented 5 years ago

Well, no luck here, still hitting the nuget issues with cake 0.35.0 and wyam 2.2.9.

error CS0012: The type 'Stream' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.IO, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
error CS0012: The type 'Task<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I'll stick to my hacky workaround I guess. Thanks anyway.