How can I resolve "Value cannot be null. Parameter name: source" exception Xamarin Forms latest Ver

JamesWarnockJamesWarnock USMember ✭✭

Before the update to 2.4.0.38779, my iPhone Application worked just fine. After the update is crashes. I didn't keep track of the previous version of xamarin forms I was on where it worked. I tend to hold off incremental updates because thins break that worked before all too often. I narrowed down the problem to this:

App.xaml file where I keep my resources and styles:

<x:String x:Key="PopUpButtonMargin">0,0,0,2</x:String>

ModalPopUpsPage.Xaml - the use of the PopUpButton Margin static resource fails:

<Button x:Name="bWhatsNextLearnMore"
Text="Learn More"
FontAttributes="Bold"
VerticalOptions="Center"
Opacity="1.0"
BorderWidth="0"
Margin="{StaticResource PopUpButtonMargin}" />

If I replace the Margin specification with Margin="0,0,0,2" instead of the static resource, it works. Use the static resource, Null Exception happens. The codes been in place for about 6 months and not failed. I've seen similar bugs like this for Xaml, linq and using on platform variants for x:String but I don't see a match to this issue but Xaml is pretty new to me.

Following is the stack dump:

at System.Linq.Enumerable.Contains[TSource] (System.Collections.Generic.IEnumerable1[T] source, TSource value, System.Collections.Generic.IEqualityComparer1[T] comparer) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.1.0/src/mono/external/corefx/src/System.Linq/src/System/Linq/Contains.cs:31
at System.Linq.Enumerable.Contains[TSource] (System.Collections.Generic.IEnumerable`1[T] source, TSource value) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.1.0/src/mono/external/corefx/src/System.Linq/src/System/Linq/Contains.cs:19
at Xamarin.Forms.Xaml.StaticResourceExtension.ProvideValue (System.IServiceProvider serviceProvider) [0x00212] in D:\agent_work\1\s\Xamarin.Forms.Xaml\MarkupExtensions\StaticResourceExtension.cs:60
at Myapp.ModalPopUpsPage.InitializeComponent () [0x0009a] in C:\Users\james\Documents\Visual Studio 2015\Projects\MyApp]MyApp.iOS\obj\iPhoneSimulator\Debug\MyApp.iOS.ModalPopUpsPage.xaml.g.cs:53
atMyApp.ModalPopUpsPage..ctor () [0x0004e] in C:\Users\james\Documents\Visual Studio 2015\Projects\MyApp\MyApp\ModalPopUpsPage.xaml.cs:5

Have I been using x:String, etc., wrong all along and the update tightened checking leading to an exception or is this a bug?

Built with Visual Studio Professional 2015
Version 14.0.25431.01 Update 3

Mac build machine has the latest Xcode updates as of 11/2/2017 along with the Xamarin Updates through Visual Studio for the Mac.

Sorry if I posted in the wrong place, but please help. I'd like to keep using Resources like x:String, etc.

Thanks.

Best Answer

  • JamesWarnockJamesWarnock USMember ✭✭
    Accepted Answer

    I figured it out.... have to use a Thickness instead of a x:String in the specification of the staticresource for the Margin.. Maybe a default value converter from string to thickness is gone in this update.

    Thanks..

Answers

  • JamesWarnockJamesWarnock USMember ✭✭

    Oops I used tags above in the post so some the info about the file contents is mostly missing.

    App.xaml file where I keep my resources and styles:

    <x:String x:Key="PopUpButtonMargin">0,0,0,2</x:String>
    

    ModalPopUpsPage.Xaml - the use of the PopUpButton Margin static resource fails

    <Button x:Name="bWhatsNextLearnMore"
    Text="Learn More"
    FontAttributes="Bold"
    VerticalOptions="Center"
    Opacity="1.0"
    BorderWidth="0"
    Margin="{StaticResource PopUpButtonMargin}" />
    
  • JamesWarnockJamesWarnock USMember ✭✭
    Accepted Answer

    I figured it out.... have to use a Thickness instead of a x:String in the specification of the staticresource for the Margin.. Maybe a default value converter from string to thickness is gone in this update.

    Thanks..

Sign In or Register to comment.