Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

unable to create product C# parameter value cannot be 0

(0) ShareShare
ReportReport
Posted on by 225

Hi,

I'm getting an exception on proxy.Create(product) line;

Parameter value cannot be 0
Parameter name: value

uom and uomschedule both exist, even tried to hardcode uom values from existing products, with the same result

here's my code:

            try
            {
                var query = new QueryByAttribute("uom");
                query.ColumnSet = new ColumnSet("name", "uomscheduleid");
                query.Attributes.AddRange("name");
                query.Values.AddRange("SZT");
                Entity unit = proxy.RetrieveMultiple(query).Entities[0];  

                Entity product = new Product()
                {
                    Name = "test product",
                    ProductNumber = "123test123",
                    Description = "asdfasdfa",
                    DefaultUoMScheduleId = (EntityReference)unit.Attributes["uomscheduleid"],
                    DefaultUoMId = unit.ToEntityReference(),
                };
                var prod = proxy.Create(product);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

I have a lot of similar creation procedures working for other entities, for a first time I have to create product,
and got stuck

will appreciate any advice,

Kind Regards

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: unable to create product C# parameter value cannot be 0

    I'm glad you were able to resolve your issue.

  • MGO Profile Picture
    225 on at
    RE: unable to create product C# parameter value cannot be 0

    You were right, there was oncreate plugin from MS Dynamics Connector, fortunatelly we do not use it anymore, after I deactivated a plugin, product has been created :D

    thx for help,

    Kind Regards

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: unable to create product C# parameter value cannot be 0

    So I have 2 news for you:

    1. Good one - there is nothing wrong with your code. Keep using it.

    2. Bad one the issue is in Microsoft.Dynamics.Integration.Adapters.Crm2011.Plugin.ProductCreateUpdateEventHandler plugin. The only recommendation that I have - download the assembly that contains that plugin, use ILSpy or .Net Reflector to see the source code, check what is missing in your code or the data inside your system.

  • MGO Profile Picture
    225 on at
    RE: unable to create product C# parameter value cannot be 0

    got back to simple code, grabbed ids from existing product to be sure,

              try

               {

                   Guid UnitGroupId = new Guid("D69877A0-8C48-493A-9CEB-9E40D9377DBC");

                   Guid unitId = new Guid("D20C830F-E7B6-E511-8B8B-00155D023200");

                   Guid priceLevelId = new Guid("9B75D209-F94A-E511-BA69-00155D023200");

                   Entity product = new Entity("product");

                   product.Attributes["name"] = "Example Product 1";

                   product.Attributes["productnumber"] = "P001";

                   product.Attributes["defaultuomscheduleid"] = new EntityReference("uomschedule", UnitGroupId);

                   product.Attributes["defaultuomid"] = new EntityReference("uom", unitId);

                   product.Attributes["pricelevelid"] = new EntityReference("pricelevel", priceLevelId);

                   Guid _product1Id = proxy.Create(product);

               }

    and I am getting

    Unexpected exception from plug-in (Execute): Microsoft.Dynamics.Integration.Adapters.Crm2011.Plugin.ProductCreateUpdateEventHandler: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 87

Overall leaderboard

Product updates

Dynamics 365 release plans