question

TaskBasic-9644 avatar image
0 Votes"
TaskBasic-9644 asked AryaDing-MSFT commented

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

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.

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AryaDing-MSFT avatar image
0 Votes"
AryaDing-MSFT answered AryaDing-MSFT commented

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.



· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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.

But I would need to compile with .NET Native tool chain to be sure the app will run on user machines, right?



0 Votes 0 ·

Local native compilation via the “Release” configuration will enable testing your application in an environment that is similar to what your customers will experience. As you said, disable the .NET Native tool chain may affect the the app running on users' machines. So Why don't use the normal way to set the ListView ItemSource instead of (dynamic(listView)).ItemSource?

0 Votes 0 ·

We are trying to set ItemsSource for any given items control. But since we've encountered this issue, the next best option would be to conditionally cast to the control type. It will work for our purposes, but it does depend on knowing the control type at design time.

0 Votes 0 ·
Show more comments