Plugin with RestSharp method not found

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Hello,

I've been developing a payment method that uses RestSharp to communicate with the payment API provider. RestSharp is installed as a nuget package in my plugin and on the project configuration file CopyLocalLockFileAssemblies is set to true in order to copy the dll to the output directory. Everything was working perfectly until I started coding a scheduled task and uninstalled the plugin and installed it again to test the task creation mechanism. After that, there was an error saying the assembly for RestSharp could not be found so I cleaned the solution and rebuilt the solution and that error was gone.

Now, every time I call my API service, even before my functions are hit, I get the following error:

Method not found: 'Void RestSharp.RestRequest..ctor(System.String, RestSharp.Method, RestSharp.DataFormat)'

This leads me to assume that the error is being triggered by the RestSharp using statement. I've googled the error and there was something about an older version having that bug but was solved in a more recent version. So, is nopcommerce loading RestSharp from another plugin that may have that older version?

Do anybody have any clue what could be going wrong here?

Thanks!
3 years ago
sounds like there is a method signature discrepancy between the binary and whatever is calling it, most likely the string is now expected to be a System.Uri type, so when you construct it with a string the method is not found
3 years ago
I've tried with a URI instead a of string in the constructor (despite both being accepted signatures) and the same error still happens. And the error happens before my breakpoint on the constructor line is hit. But if I comment out the constructor then there is no error. It seems like something is checking it at runtime and doing something strange behind the scenes.

But the most strange thing is that it was working perfectly before I uninstalled and reinstalled my plugin. What could that have changed?

Thanks!
3 years ago
I figured out that the sendinblue plugin (and others) also uses restsharp and they were overwriting my dll in the plugins/bin folder. So I removed them from the plugins folder and now only my restsharp is written to plugins/bin and everything is working again.

But how do I ensure that in production environment my RestSharp dll version doesn't get overwritten by other plugins RestSharp dll?
3 years ago
Thats interesting I am using RestSharp in my plugin as well !
This is what I have in my projet file

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="RestSharp" Version="106.10.1" />
  </ItemGroup>
  
  <ItemGroup>
    <None Update="Newtonsoft.Json.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="RestSharp.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

Do you have the same or something else ?
3 years ago
I Have the PackageReference but don't have the:

<ItemGroup>
    <None Update="RestSharp.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

I also have:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

I will add the ones I'm missing but so far it works as I removed the other plugins so can't really test for now.
3 years ago
When trying to deploy the plugin to production server the error (expectedly) creeped back up.
I've tried adding those lines you mentioned that I was missing but didn't change anything. I've also tried changing the display order of the plugin to higher number with no luck.

My RestSharp constructor call looks like this:

var uri = isSandbox ? new Uri("https://xxx.xx") : new Uri("https://xxx.xx");
var client = new RestClient(uri);

But I've also tried with:

var client = isSandbox ? new RestClient("https://xxx.xx") : new RestClient(" https://xxx.xx");

Do yours look different?

I'd like to know how to make sure that my dll gets copied into the bin folder (and then I would have no problems with the constructor error). Do you have any clue how to achieve this?
3 years ago
This is due to DLL conflict with the bundle RestSharp from some default payment plugins in Nop (Square and Qualpays). If you are using Nop 4.2, it has an older version of RestSharp under those plugins and sometimes, it would pick those up instead of the DLL from Nuget package in your plugin instead. If you do not might touching the Nop core source code, then get the same DLL from Nuget package and copy it over to those plugins that using the library and that will resolve the issue.
3 years ago
Thanks Spincel,

That is exactly what I've done, replacing the other plugins dll with mine (in addition to the plugins you mentioned sendinblue plugin also has the bad dll). But if I want to distribute the plugin in marketplace then this solution won't work as other people will also experience this problem. I was looking for a more automated way of solving it.
2 years ago
Hey guys I had the same problem. I solved it as you suggested. But does anyone know a better solution to this workaround ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.