Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

XmlnsDefinitionAttribute: ArgumentNullException - Parameter name: clrNamespace

$
0
0

I am using the method LoadFromXaml in Xamarin.Forms.Xaml.Extensions. This method allows for dynamic creation of UI elements from Xaml strings at runtime. I'm using this via reflection because it is an internal method. The Xamarin Forms team have refused to make this method public for some reason, but we require this functionality so we are forced to use this reflection hack.

We've been using this functionality for several months now without a problem. But, today, when I ran the latest code, I got an exception when parsing our dynamically loaded Xaml (which hasn't changed). This has stopped development dead in its tracks for us because I can't run our app at all now.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: clrNamespace
at Xamarin.Forms.Internals.XmlnsDefinitionAttribute..ctor(String xmlNamespace, String clrNamespace)
at Xamarin.Forms.Xaml.XamlParser.GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, XamlParseException& exception)
at Xamarin.Forms.Xaml.Internals.XamlTypeResolver.Resolve(String qualifiedTypeName, IServiceProvider serviceProvider, XamlParseException& exception)
at Xamarin.Forms.Xaml.Internals.XamlTypeResolver.Xamarin.Forms.Xaml.IXamlTypeResolver.TryResolve(String qualifiedTypeName, Type& type)
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.MarkupExpansionParser.Parse(String match, String& remaining, IServiceProvider serviceProvider)
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.ParseExpression(String& expression, IXmlNamespaceResolver nsResolver, IXmlLineInfo xmlLineInfo, INode node, INode parentNode)
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.Visit(MarkupNode markupnode, INode parentNode)
at Xamarin.Forms.Xaml.MarkupNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.XamlLoader.Visit(RootNode rootnode, HydratationContext visitorContext)
at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, String xaml)
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, String xaml)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Adapt.Presentation.XamarinForms.XamlReader.<>c__DisplayClass1_0.<.cctor>b__2(BindableObject view, String xaml)
at Adapt.Presentation.XamarinForms.XamlReader.LoadFromXaml[TView](TView view, String xaml)
at Adapt.Presentation.XamarinForms.XamlReader.LoadFromXaml[TView](String xaml)
at Adapt.Presentation.Xivic.Navigation.TabbedPageUIController.CreateAndAddPanelFromContent(PagePanel pagePanel, Nullable`1 panelHeight)
at Adapt.Presentation.Xivic.PanelPageBase.d__22.MoveNext()

I thought it might be a problem with our XAML, but it's happening with all the XAML that has always worked in the past. Here is an example of our XAML:

<ContentView xmlns:local="clr-namespace:Adapt.Presentation.XamarinForms.Controls;assembly=Adapt.Presentation.XamarinForms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
  <Grid>

    <Grid.RowDefinitions>
      <RowDefinition Height="60" />
      <RowDefinition  />
    </Grid.RowDefinitions>

    <local:BasicRecordProvider RecordTypeName="Adapt.Model.Custom.ContractorDef"  x:Name="ContractorDefs" />

    <local:AdaptPicker Title="Client" ItemsSource="{Binding Source={x:Reference Name=ContractorDefs}}" DisplayMemberPath="Code" SelectedItem="{Binding Contractor, Mode=TwoWay}" />

    <Editor Text="{Binding ProbNotes}" TextColor="#FF0000EE" Grid.Row="1" />

  </Grid>

</ContentView>

I sifted through the Xamarin Forms code in the Git Repo, and traced the error message to this spot. It's in the constructor of XmlnsDefinitionAttribute (https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs).

    public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
    {
        if (xmlNamespace == null)
            throw new ArgumentNullException(nameof(xmlNamespace));
        if (clrNamespace == null)
            throw new ArgumentNullException(nameof(clrNamespace));

        ClrNamespace = clrNamespace;
        XmlNamespace = xmlNamespace;
    }

Note: I am using Xamarin Forms build 2.3.4.224. I have also tried upgrading to 2.3.4.231 (with a full Git Clean of my solution folders), and this made no difference.

I presume the problem has something to do with the Xml namespace, but I can't see what the issue would be here. Does anyone here have any ideas?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>