wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
342 stars 130 forks source link

Delete requests do not work when WordPressPCL NuGet package is used in .NET Framework project #113

Closed zielo-it closed 6 years ago

zielo-it commented 6 years ago

Problem exists when execution is dealing with HttpResponseMessage type. My project uses .NET Framework 4.6.1. When I copied WordpressPCL project into my solution and changed HttpHelper.DeleteRequest method to return Task<bool> instead of Task<HttpResponseMessage> code began to work. Otherwise I get following MissingMethodException:

'System.MissingMethodException : Method not found: 'System.Threading.Tasks.Task'1<System.Net.Http.HttpResponseMessage> WordPressPCL.Client.CustomRequest.Delete(System.String)'.

I've used WordPressPCL v1.4.0

ThomasPe commented 6 years ago

can you share a repo of this?

zielo-it commented 6 years ago

https://github.com/zielo-it/wordpress-pcl-usecase

polushinmk commented 6 years ago

Hi @zielo-it ! I foud a fix. It seems, that it is problem in System.Net.Http module. You should change in app.config from:

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.3" newVersion="4.3.3" />
      </dependentAssembly>

to

<dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>

It works for me.

@ThomasPe what do you think about changing return value of Delete function from HttpResponseMessage to bool?

ThomasPe commented 6 years ago

Huh, interesting. I'm ok with changing this to bool since it will throw an exception if anything goes wrong anyway, right?

polushinmk commented 6 years ago

I see 2 options: 1) throw an exception, when Delete request cannot be execute 2) return not only bool, but bool+string. string - info message. If bool true - info null, if bool false - info contains responce from WP

but it is another BC :( All users must changed there delete method usages

UPD now we already throws exceptions if delete request cannot be execute, so second option cannot be realised

ThomasPe commented 6 years ago

I think I would prefer the first one - do you have a preference?

zielo-it commented 6 years ago

First option works for me :+1:

ThomasPe commented 6 years ago

I've just updated the NuGet package, should be available in the next hour or so.

polushinmk commented 6 years ago

@ThomasPe but you didn`t merge this pr #114 . Are you missed it?

ThomasPe commented 6 years ago

oh no, I did o.O give me a sec

ThomasPe commented 6 years ago

Look for version 1.4.2 😉