RuntimeBinderException when setting ((dynamic)ListView).ItemsSource in Release mode only

ishebewhat 61 Reputation points
2021-05-10T06:58:32.317+00:00

This issue can be reproduced easily. In a new project add a ListView (LV) and in the code-behind add the following line of code:

((dynamic)LV).ItemsSource = new List<string>();

Run in Debug mode and Release mode. In Release mode, a RuntimeBinderException will be thrown with the following message:

"Unhandled exception at 0x7B786011 (Windows.UI.Xaml.dll) in TestApp.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x06182CB0, 0x00000003)."

Then replace the line of code above with the following line of code:

LV.ItemsSource = new List<string>();

There will be no exception in either mode.

Developer technologies Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AryaDing-MSFT 2,916 Reputation points
    2021-05-11T07:42:17.077+00:00

    Hi,
    Welcome to Microsoft Q&A!

    This issue might be related with the Native .NET tool chain. The Compile with .NET Native tool chain build option is activated for release builds of UWP projects, but deactivated for debug builds per default. This is a good idea in principle, because the long build time of the Native tool chain would be impossible to use for frequent test runs during development. The compiler and the .NET Native tool chain seem to produce slightly different IL code in certain scenarios, sometimes which leads to bug tickets stating that an app behaves not as specified which are not reproducible in debug mode.

    In release mode, you could right click the project and select the option Properties, then disable the Compile with .NET Native tool chain in build tab, so that the code will work well. However, for more performance, I suggest you use the normal way( LV.ItemsSource = new List<string>(); ) to setting Itemsource in Debug mode.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.