Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to add an entity throws CLR/System.InvalidOperationException #472

Open
victorBuzdugan opened this issue Mar 4, 2024 · 2 comments

Comments

@victorBuzdugan
Copy link

Prestashop version: 8.1.3 but I think it's unrelated to Prestashop version

Trying to add a manufacturer using either Add or AddAsync methods throws an exception at line 186 (using AddAsync) or at line 46 (using Add) in GenericFactory.cs:

Exception has occurred: CLR/System.InvalidOperationException
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll: 'Nullable object must have a value.'

In order to reproduce:

  • Clone the GitHub repo
  • Add a new console project to the solution
  • Add PrestaSharp ass a reference to the project
  • In Program.cs:
using Bukimedia.PrestaSharp.Entities;
using Bukimedia.PrestaSharp.Factories;

string url = "http://localhost/prestashop/api";
string account = "<api_key>";
string secretKey = "";
string manufacturerName = "TestManufacturer";
ManufacturerFactory manufacturerFactory = new ManufacturerFactory(url, account, secretKey);

// just to test that credentials are correct
List<manufacturer> manufacturers = manufacturerFactory.GetAll();

var newManufacturer = new manufacturer();
newManufacturer.name = manufacturerName;
newManufacturer.active = 1;
newManufacturer = manufacturerFactory.Add(newManufacturer);
// or
newManufacturer = await manufacturerFactory.AddAsync(newManufacturer);

Reverting back before Merge pull request #469 fixes the issue:

git reset 0121cc0 --hard

Looking at the AddBody method (that was change in pull request 469) in RestSharpFactory.cs I can see that entities is not used and serialized is just an empty string:

private void AddBody(RestRequest request, IEnumerable<PrestaShopEntity> entities)
{
    request.RequestFormat = DataFormat.Xml;
    var serialized = string.Empty;
    serialized = "<prestashop>\n" + serialized + "\n</prestashop>";
    request.AddParameter("application/xml", serialized, ParameterType.RequestBody);
}
@sginfoocio
Copy link

Hi, any update of this

private void AddBody(RestRequest request, IEnumerable entities)
{
request.RequestFormat = DataFormat.Xml;
var serialized = string.Empty;
serialized = "\n" + serialized + "\n";
request.AddParameter("application/xml", serialized, ParameterType.RequestBody);
}

Thanks

@sanctusmob
Copy link
Contributor

This issue has been fixed in pull request #482.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants