web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

I have the same question (0)
  • MGO Profile Picture
    225 on at

    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.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

    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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 85 Super User 2026 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#3
11manish Profile Picture

11manish 64

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans