Developer forum

Forum » Development » Crashes when adding product

Crashes when adding product

Per Ljung
Reply
Hi!

I'm trying to add a product:

product = Product.Create("");

            product.addGroup(new Group("hej"));

            product.ID = "A333";
            product.Number = "A333";
            product.Name = "test";

            product.DefaultShopID = Shop.getShops(true).get_Item(0).ID;

            product.LanguageID = Dynamicweb.eCommerce.Common.Context.LanguageID;

            product.Save();
But always get this error:

[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.eCommerce.Common.Context.set_LanguageID(String Value) +60
   Dynamicweb.eCommerce.Common.Context.get_Language() +71
   Dynamicweb.eCommerce.Common.Context.get_LanguageID() +78
   Dynamicweb.eCommerce.Products.Product..ctor(String ProductID, String VariantId, String languageId) +493
   Dynamicweb.eCommerce.Products.Product.Create(String ProductID, String VariantId, String languageId) +238
   Dynamicweb.eCommerce.Products.Product.Create(String ProductID, String VariantId) +11
   Dynamicweb.eCommerce.Products.Product.Create(String ProductID) +11
   DwModule.Commands.ImportProducts() +146
   DwModule.Commands.ProcessRequest(HttpContext context) +141
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Looks like there's some problem with the language settings...

Best regards,
Per


Replies

 
Morten Snedker
Reply
 Hi Per,

You should think of context as being the frontend (session scope). So, if you execute the code and there is no frontend, the langauge of the context has not been set (Object reference not set to an instance of an object).

If you believe that a context language should be present at runtime of you code, please post the entire code for review.

Please let me know if you get it to work.

Regards /Snedker
 
Per Ljung
Reply


Hi, I solved it (almost).

It worked when I placed the code in an aspx-file and referred to it in the setting "Script" in the module preferences.

But I wonder how to solve this when I have an aspx handler that triggers product import/order export etc. How do I do to connect this to Dynamicweb? I first thought that the only thing you had to do was to place the code on the dw server, but as I said, it didn't work that way.
 

Best regards,

Per

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer
Hi Per,

The API relies on Session state, so your handler needs to support that as well. You need to derrive your handler from IRequiresSessionState  like this:

public class YourHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState

Hope this helps,

Imar
Votes for this answer: 0
 
Per Ljung
Reply


That solved it, thanks!
 

/Per

 

You must be logged in to post in the forum