MethodBoundaryAspect.Fody icon indicating copy to clipboard operation
MethodBoundaryAspect.Fody copied to clipboard

Invalid program with specific method

Open Ralf1108 opened this issue 4 years ago • 2 comments

This method lead to an "Invalid program" exception during runtime. Removing "DisplayWaitCursor" attribute fixes the problem This should be tried to reproduce.

[DisplayWaitCursor]
        private async Task Add(InvoiceContactViewModel contactViewModel)
        {
            if (contactViewModel == null)
                return;            if (ChosenContactViewModels.Contains(contactViewModel))
                return;            if (ShowOnlyContactsWithoutIncidents)
            {
                var hasContactIncident = await HasContactIncident(contactViewModel);                if (hasContactIncident)
                {
                    _show.Error(
                        MultipleContactSelectionDialogResources.AssignContactToCorporationHint,
                        contactViewModel.Contact.AdvancedEntityText);                    return;
                }
            }            var removeItem = AvailableContactViewModels
                .SingleOrDefault(x => x.Contact.ID == contactViewModel.Contact.ID);            ChosenContactViewModels.Add(contactViewModel);            if (removeItem != null)
                AvailableContactViewModels.Remove(removeItem);
        }

Ralf1108 avatar Oct 01 '21 12:10 Ralf1108

Without the additional code, it is impossible to reproduce the error from your example.

That said, this looks like it matches the pattern of a method ending in a code block (if (removeItem != null) { AvailableContactViewModels.Remove(removeItem); }) related to issue #66. A simple work around is to simply add another line of code after the block. (for example, end the method with await Task.CompletedTask;)

I'm currently researching a better solution.

psaxton avatar Sep 16 '22 20:09 psaxton

I believe this issue to be resolved in PR #100.

psaxton avatar Oct 04 '22 21:10 psaxton