Windowscommunitytoolkit: ImageEx create instance issue with Windows Community toolkit version 6.0.0

Created on 15 Nov 2019  路  17Comments  路  Source: windows-toolkit/WindowsCommunityToolkit

## Describe the bug
Upgrde to 6.0.0 return unhandled exception for ImageEx.
UNHANDLED EXCEPTION: Cannot create instance of type 'Microsoft.Toolkit.Uwp.UI.Controls.ImageEx' [Line: 0 Position: 0]: 

- [X] Is this bug a regression in the toolkit?  If so, what toolkit version did you last see it work: 5.1.1

## Steps to Reproduce
Steps to reproduce the behavior:
1. UWP App, Add ImageEx control to a view (xaml file). 
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls" 

            <toolkit:ImageEx Grid.Row="0" Source="{Binding data.Thumbnail}" HorizontalAlignment="Center" VerticalAlignment="Center" PlaceholderSource="/Assets/Icons/iconPlaceHolder.png" IsCacheEnabled="True" AllowDrop="True" Visibility="{Binding data.Thumbnail, Converter={StaticResource NullToVisibilityConverter}}" IsEnabled="True" CachingStrategy="Internal"  />

2. Use toolkit version 5.1.1,  build app.
3. run app.
4. update toolkit version to 6.0.0 
5. build and run app 
6. app crashes.

## Expected behavior
app should run without any issues.

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [X] May 2019 Update (18362)
- [ ] Insider Build (build number: )

App min and target version:
- [X] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [X] 2017 (version: )


bug controls help wanted unable to reproduce

All 17 comments

Thanks @rku-agnitio, we'll take a look. @Kyaa-dost can you reproduce this on your machine?

@rku-agnitio I have tried this multiple times today and was not able to reproduce at all. What version of VS are you using? I am using Visual Studio 2019 V16.3.7 and is working completely fine.

HI,
I can reproduce it again.
I am using VS2017 15.9.17.
I haven\t tested with 2019.
I will test with 2019 and let you know.

Regards,
Renu Kumar

Thanks @Kyaa-dost and @rku-agnitio. We did update our own tool chain to 2019, but I'm surprised that it'd invalidate it from working in 2017 as a NuGet package.

@rku-agnitio, what version of the Microsoft.NETCore.UniversalWindowsPlatform are you using? I wonder if that could be related as well.

@LyalinDotCom any thoughts on the tooling side about what could be going on here?

HI,
I am using 6.2.9.
It is interesting to know in detail.
Let me know your further findings and recommendations.

Regards,
Renu Kumar

I saw the same issue with RadialGradientBrush control using Microsoft.Toolkit.Uwp.UI.Media version 6.0.0.

UNHANDLED EXCEPTION: Cannot create instance of type 'Microsoft.Toolkit.Uwp.UI.Media.RadialGradientBrush'

Other controls from this NuGet package work fine.

Hi,
Now I upgraded to Visual studio 2019 latest version and still issue exists.

WinRT originate error - 0x80131513 : 'System.MissingMethodException: Method not found: 'System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken Windows.UI.Xaml.FrameworkElement.add_EffectiveViewportChanged(Windows.Foundation.TypedEventHandler`2)'.
at Microsoft.Toolkit.Uwp.UI.Controls.ImageExBase..ctor()
at Microsoft.Toolkit.Uwp.UI.Controls.ImageEx..ctor()
at company_product_XamlTypeInfo.XamlTypeInfoProvider.Activate_90_Im'.
onecore\com\combase\winrt\error\restrictederror.cpp(1014)\combase.dll!00007FFBAD6A34A0: (caller: 00007FFBAD68CA0C) ReturnHr(8) tid(4974) 8007007E The specified module could not be found.
Exception thrown at 0x00007FFBACD0A859 (KernelBase.dll) in company.product.exe: WinRT originate error - 0x802B000A : 'Cannot create instance of type 'Microsoft.Toolkit.Uwp.UI.Controls.ImageEx' [Line: 141 Position: 328]'.

Hi @rku-agnitio, just a thought on this as we experienced a lot of toolchain problems (outside of the Community toolkit space) with our own product as well.
Do you see the MissingMethodException only in Release builds of your app? If so the optimizer might have removed required code and you need to adjust your app's rd.xml to omit everything related to the Microsoft toolkit nuget packages from optimization.

Hi @s-beltz , it is not release build. I am experiencing with debug builds. I haven't tested with release build yet.

I'm experiencing the same issue with ImageEx.
Admittedly, I have no idea when it stopped working...it's been a long time since I've touched this application.

VS Community 2019 v16.5.2
UWP v6.2.10
Microsoft.Toolkit.Uwp.UI.Controls v6.0.0
Referencing multiple libraries using NETStandard.Library v2.0.3

When I first pulled the source code back out and blew the dust off of it, I got a "pipeline broken" compile error. I found something on the internet that said remove the Nuget package for AdaptiveTriggersLibrary. Doing that fixed the "pipeline broken" issue. Then I began getting this runtime error.
The ImageEx control exists in multiple UserControls that are used for ItemTemplates in ListViews. I replaced the ImageEx control with an Image control in the 1st UserControl, only to have the exception pop up referencing the ImageEx in the UserControl used in the 2nd ListView.

Just started using ImageEx and I'm experiencing the same issue at random intervals.

Windows 10 Build Number:

  • [ ] Fall Creators Update (16299)
  • [ ] April 2018 Update (17134)
  • [ ] October 2018 Update (17763)
  • [X] May 2019 Update (18362)
  • [ ] Insider Build (build number: )

App min version:

  • [X] Fall Creators Update (16299)
  • [ ] April 2018 Update (17134)
  • [ ] October 2018 Update (17763)
  • [ ] May 2019 Update (18362)
  • [ ] Insider Build (xxxxx)

App target version:

  • [ ] Fall Creators Update (16299)
  • [ ] April 2018 Update (17134)
  • [ ] October 2018 Update (17763)
  • [X] May 2019 Update (18362)
  • [ ] Insider Build (xxxxx)

Device form factor:

  • [X] Desktop
  • [ ] Xbox
  • [ ] Surface Hub
  • [ ] IoT

Visual Studio

  • [X] 2019 (version: 16.5.1)

Nothing changed in ImageEx between 5.1.1 and 6.0.0 (the code wasn't touched last year at all in fact). There has to be some other tooling/dependency issue going on here, @Kyaa-dost can you try again with a VS 2019 16.5.x build as that seems to be some commonality above?

The only hint is what @rku-agnitio pointed to here about the missing method exception for the EffectiveViewPort registration:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/2a9e2e9bd267b855a3fcc33a9acf7895efe22ba4/Microsoft.Toolkit.Uwp.UI.Controls/ImageEx/ImageExBase.cs#L83-L86

But if it's doing the registration, it's already done the check for the if condition from here:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/2a9e2e9bd267b855a3fcc33a9acf7895efe22ba4/Microsoft.Toolkit.Uwp.UI.Controls/ImageEx/ImageExBase.Members.cs#L62

Which I'm wondering if we should be using a string instead of nameof @azchohfi, thoughts? But still, that hadn't changed between packages.

@MattWhilden wondering if you have any thoughts on what else could be in play here?

Hi @michael-hawker

I too am getting the following since upgrading from 5.1.1 to 6.0.0.

UWP is at 6.2.10.

Method not found: 'System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken Windows.UI.Xaml.FrameworkElement.add_EffectiveViewportChanged(Windows.Foundation.TypedEventHandler`2)'.

Maybe there is some munging during the build, so nameof(EffectiveViewportChanged) != "EffectiveViewportChanged"?

@MichalStrehovsky @tommcdon any thoughts on what might have happened here to cause this MissingMethodException? Is there some platform issue that was discovered that need a certain set of updates to work around? Thanks!

nameof is evaluated at compile time, so it shouldn't matter. I don't know what is happening.

I made a blank UWP app, set MinVersion to Fall Creators update, Target to 1903, added a reference to the UI.Controls 6.0 nuget package, dropped an ImageEx on the form and set the Source to a random internet URL, switched to Release config and deployed. I don't see a repro.

Thanks @MichalStrehovsky for taking a look. I'm going to close this out for now as no one on our side has been able to reproduce the problem.

@rku-agnitio @r2d2rigo if you have an isolated repro project to share, let us know and attach and we can test again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karmaecrivain94 picture karmaecrivain94  路  3Comments

SmartPolarBear picture SmartPolarBear  路  4Comments

nolanblew picture nolanblew  路  3Comments

michael-hawker picture michael-hawker  路  3Comments

kusanagi2k2 picture kusanagi2k2  路  4Comments