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

Exception in property changed event #92

Open
dazinator opened this issue Jan 13, 2023 · 0 comments
Open

Exception in property changed event #92

dazinator opened this issue Jan 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@dazinator
Copy link

dazinator commented Jan 13, 2023

Describe the bug

I have generated the client based on metadata file downloaded from a vanilla dev instance of Microsoft Dynamics 365 Finance and Operations.

I ticked the option to generate property change tracking, and also "async base" for c# only (not sure what that means precisely. I should also say, I am runnign the version from this PR: #87 as that fixes an issue with spaces being in generated method names.

I wrote a quick console app to new up the client, and post a header record with a related child record, using a single change set.

I haven't managed to get this to work just yet, I have been able to post a header on its own however thats a seperate issue.
Sometimes when I run the app I see this:

image

Here is how I am using:

       var serviceRootUri = new Uri($"{url}/data");
       var dataServiceContext = new Resources(serviceRootUri);
       dataServiceContext.SendingRequest2 += (sender, eventArgs) =>
        {
            var request = eventArgs.RequestMessage;        
            eventArgs.RequestMessage.SetHeader("Authorization", $"Bearer {token.Token}");
        };
        
        var item = new Microsoft.Dynamics.DataEntities.LedgerJournalHeader();      
        // dataServiceContext.AddToLedgerJournalHeaders(item); // in order to use PostOnlySetProperties it seems necessary to use DataServiceCollection instead.
             
        var col = new DataServiceCollection<Microsoft.Dynamics.DataEntities.LedgerJournalHeader>(dataServiceContext);    
        col.Add(item);

       // after adding the item to the collection, we sets its properties, this is so that change tracking works, and PostOnlySetProperties works.
        item.DataAreaId = "DEMF";
        item.JournalName = "GenJrn";
        item.Description = "Posted by poc";      

        var linesCol = new DataServiceCollection<Microsoft.Dynamics.DataEntities.LedgerJournalLine>(dataServiceContext);
        for (int i = 0; i < 2; i++)
        {
            var amount = 100000;
            if (i % 2 == 0)
            {
               
            }
            else
            {
                amount = -amount;
            }

            var line = new Microsoft.Dynamics.DataEntities.LedgerJournalLine();
            linesCol.Add(line);
            // after adding the item to the collection, the following just sets its propertie, this is so that change tracking works, and PostOnlySetProperties works.
            SetLine(line, item.DataAreaId, item.JournalBatchNumber, amount);

            dataServiceContext.AddLink(item, nameof(item.LedgerJournalLine), line);
            dataServiceContext.SetLink(line, nameof(line.LedgerJournalHeader), item);         
        }

   
        await dataServiceContext.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset | SaveChangesOptions.PostOnlySetProperties);   

Assemblies affected

As per above,

Expected result

Wouldn't expect an exception here.

Actual result

Exception thrown when the generated property change handlers are iterated due to some concurrency issue.

Screenshots

As per above.

Additional detail

Add any other context about the problem here.
*Optional, details of the root cause if known.

@dazinator dazinator added the bug Something isn't working label Jan 13, 2023
@dazinator dazinator mentioned this issue Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant