Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
155 stars 152 forks source link

"Nullable object must have a value" when creating product or combination #303

Closed gvd12 closed 6 years ago

gvd12 commented 6 years ago

Hi, I'm getting the following error when trying to create a new product or a new combination on the production server. it seems to be working just fine on the test server, so I guess it's something config related, but I can't figure what it is causing it.

Whenever it tries to create the product and reaches to ProductFactory.cs / public Entities.product Add(Entities.product Product) it returns a null value on return this.Get((long)aux.id); . The exception is System.InvalidOperationException: 'Nullable object must have a value.'

Any idea of what can be happening?

Thanks in advance.

Just some brief snippets of the code showing the path it is going.

objProduct = _PSTOOLS.AddProduct(objProduct);

public static product AddProduct(product newProduct)
        {
            return myProductFactory.Add(newProduct);
        }

private static ProductFactory myProductFactory;

myProductFactory = new ProductFactory(BaseUrl, Account, "");

public Entities.product Add(Entities.product Product)
        {

            long? idAux = Product.id;
            Product.id = null;

            List<PrestaSharp.Entities.PrestaShopEntity> Entities = new List<PrestaSharp.Entities.PrestaShopEntity>();
            Entities.Add(Product);
            RestRequest request = this.RequestForAdd("products", Entities);

            Entities.product aux = this.Execute<Entities.product>(request);
            Product.id = idAux;

            return this.Get((long)aux.id);
        }

Here is the full stack:

StackTrace  "   en System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)\r\n  
en System.Nullable`1.get_Value()\r\n  
en Bukimedia.PrestaSharp.Factories.ProductFactory.Add(product Product) 
en Z:\\SVN_\\Client\\erp2Prest\\PrestaSharp-master\\Factories\\ProductFactory.cs:línea 38\r\n   
en erp2Prest._PSTOOLS.AddProduct(product newProduct) 
en Z:\\SVN_\\Client\\erp2Prest\\erp2Prest\\_PSTOOLS.cs:línea 297\r\n   
en erp2Prest.FrmSync.CreateProductGroup(String ArtRef)
en Z:\\SVN_\\Client\\erp2Prest\\erp2Prest\\Forms\\FrmSync.cs:línea 558\r\n   
en erp2Prest.FrmSync.SyncArticles(List`1 refList, Boolean booUpdateStock, Boolean booUpdatePrice) 
en Z:\\SVN_\\Client\\erp2Prest\\erp2Prest\\Forms\\FrmSync.cs:línea 176\r\n   
en erp2Prest.FrmSync.btnSync_Click(Object sender, EventArgs e) 
en Z:\\SVN_\\Client\\erp2Prest\\erp2Prest\\Forms\\FrmSync.cs:línea 1045\r\n   
en System.Windows.Forms.Control.OnClick(EventArgs e)\r\n  
en System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   
en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n   
en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n  
en System.Windows.Forms.Control.WndProc(Message& m)\r\n   
en System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n   en System.Windows.Forms.Button.WndProc(Message& m)\r\n  
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n   
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n  
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n   
en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n   
en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)\r\n  
en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   
en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   
en System.Windows.Forms.Application.Run(Form mainForm)\r\n   
en erp2Prest.Program.Main() en Z:\\SVN_\\Client\\erp2Prest\\erp2Prest\\Program.cs:línea 19" string
gvd12 commented 6 years ago

Hi,

Updated prestasharp to the last version but I'm getting the same problem( 'tho it was not much older)

This is the XML from the request on RequestForAdd on the NOT working server: https://codebeautify.org/xmlvalidator/cbb48177

Aren't those <language id= out of place?

Any ideas?

Thanks.

gvd12 commented 6 years ago

looks like it was a server side problem. Still investigating it, but nothing related to code perse.

B4N-m3 commented 5 years ago

looks like it was a server side problem. Still investigating it, but nothing related to code perse.

hi, i'm having the same problem. how do you solve it?

gvd12 commented 5 years ago

hi, It was a weird issue with the URL we were using on our config. For some reason, we were sending the petitions as http:// and the server was responding with https:// which we were receiving as blank. Forcing the use on https on our app solved the issue.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.