Occasionally Visual Studio just gives up on building the solution. Running a Xamarin Forms solution sometimes throws a compile error with the message: Value cannot be null. Parameter name: method pertaining to my .XAML files, Line 1. The issue happens even when: 1) the solution was building and running fine on the previous run. I change something in the code, re-run it and the errors shows up 2) Undoing that change and retrying the build 3) the solution was Cleaned and Rebuilt 4) either building an Android or iOS Xamarin Forms project The issue resolves itself when I restart all instances of Visual Studio. The error seems to happen on some (but not all) Xaml files in my Xamarin Forms .NET Standard project. Output: 1>App.xaml : error : Value cannot be null. 1>App.xaml : error : Parameter name: method 1>Screens\About.xaml : error : Value cannot be null. 1>Screens\About.xaml : error : Parameter name: method 1>Screens\Landing.xaml : error : Value cannot be null. 1>Screens\Landing.xaml : error : Parameter name: method 1>Screens\MasterPage.xaml : error : Value cannot be null. 1>Screens\MasterPage.xaml : error : Parameter name: method 1>Screens\Onboarding.xaml : error : Value cannot be null. 1>Screens\Onboarding.xaml : error : Parameter name: method 1>Screens\RequiredAction.xaml : error : Value cannot be null. 1>Screens\RequiredAction.xaml : error : Parameter name: method 1>Screens\Settings.xaml : error : Value cannot be null. 1>Screens\Settings.xaml : error : Parameter name: method 1>Screens\Splash.xaml : error : Value cannot be null. 1>Screens\Splash.xaml : error : Parameter name: method 1>Screens\UpgradeRequired.xaml : error : Value cannot be null. 1>Screens\UpgradeRequired.xaml : error : Parameter name: method
View on Developer Community
To find diagnostic information, see the original linked feedback ticket.
@StephaneDelcroix I guess the work item here is to suggest how the user can capture a stack trace for the exception. Is there a log file? Or short of that, instructions for how they might attach a debugger? I can't say I've encountered that particular build issue...
Thanks for reporting this. Unfortunately the provided information are very thin, and there's nothing we can infer from them.
If this happens again, could you please get us a diagnostic build (enable diagnostic build in VisualStudio) and reopen this issue ? Thanks a lot.
We are getting this issue as well, and are having a hard time figuring out what to do about it.
It happens all the time when we add [XamlCompilation(XamlCompilationOptions.Compile)] to certain classes where the xaml contains either a Label or an Entry which has FontSize or TextColor set. This happens if the values for those attributes are bound or static, but if we delete those attributes, the build error goes away.
Also, this only happens on the iOS project, not the Android one, and it happens both in Visual Studio for 2017 for Mac and Windows.
Can anyone explain how to get around this, or what might be causing it, or how to further diagnose the issue?
Here is the pertinent section of a diagnostic build showing the error:
Resource: Notes.iOS.Controls.InlineListRow.xaml
__InitComponentRuntime already exists... not creating
Parsing Xaml
done.
Replacing 0.InitializeComponent ()
failed.
/Source/SharedUI/Controls/InlineListRow.xaml : error : Value cannot be null.
/Source/SharedUI/Controls/InlineListRow.xaml : error : Parameter name: method
at Mono.Cecil.Cil.Instruction.Create (Mono.Cecil.Cil.OpCode opcode, Mono.Cecil.MethodReference method) [0x00003] in <290d5be6f83b4b02ad4ec17da62d87cd>:0
at Xamarin.Forms.Build.Tasks.NodeILExtensions+<PushServiceProvider>d__10.MoveNext () [0x00404] in <257eb4bede7a4b3891a8e331dc60e71e>:0
at Xamarin.Forms.Build.Tasks.NodeILExtensions+<PushConvertedValue>d__5.MoveNext () [0x0044c] in <257eb4bede7a4b3891a8e331dc60e71e>:0
at Xamarin.Forms.Build.Tasks.SetPropertiesVisitor+<SetValue>d__46.MoveNext () [0x00149] in <257eb4bede7a4b3891a8e331dc60e71e>:0
at Xamarin.Forms.Build.Tasks.ILProcessorExtensions.Append (Mono.Cecil.Cil.ILProcessor processor, System.Collections.Generic.IEnumerable`1[T] instructions) [0x00017] in <257eb4bede7a4b3891a8e331dc60e71e>:0
at Xamarin.Forms.Build.Tasks.SetPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, Xamarin.Forms.Xaml.INode parentNode) [0x000f6] in <257eb4bede7a4b3891a8e331dc60e71e>:0
at Xamarin.Forms.Xaml.ValueNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00000] in <0c508f2d6c0d4d96899823437fe0e09a>:0
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in <0c508f2d6c0d4d96899823437fe0e09a>:0
at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in <0c508f2d6c0d4d96899823437fe0e09a>:0
at Xamarin.Forms.Build.Tasks.XamlCTask.TryCoreCompile (Mono.Cecil.MethodDefinition initComp, Mono.Cecil.MethodDefinition initCompRuntime, Xamarin.Forms.Build.Tasks.ILRootNode rootnode, System.Exception& exception) [0x00429] in <257eb4bede7a4b3891a8e331dc60e71e>:0
Also, for comparison - if I remove the FontSize attribute from the XAML for this class, it builds without error and here is the corresponding section in the diagnostic build output:
Resource: Notes.iOS.Controls.InlineListRow.xaml
Creating empty InlineListRow.__InitComponentRuntime
done.
Copying body of InitializeComponent to __InitComponentRuntime
done.
Parsing Xaml
done.
Replacing 0.InitializeComponent ()
done.
Optimizing IL
done.
I've experienced an issue when Xamarin build changes between Android and iOS. It might be possible to workaround by the following sequence:
I'm getting a similar stack trace. The app which I am using is one created with the wizard with just an App.xaml and the MainPage.xaml "Welcome to Xamarin.Forms!" page (I was using it to test something else). I have just changed from iOS to Android and get this error.
@StephaneDelcroix, can this be re-opened, please?
Module: Ils.dll
Resource: Ils.App.xaml
Creating empty App.__InitComponentRuntime
done.
Copying body of InitializeComponent to __InitComponentRuntime
done.
Parsing Xaml
done.
Replacing 0.InitializeComponent ()
failed.
App.xaml : error : Value cannot be null.
App.xaml : error : Parameter name: type
at Mono.Cecil.Mixin.CheckType(Object type)
at Mono.Cecil.ModuleDefinition.ImportReference(TypeReference type, IGenericParameterProvider context)
at Xamarin.Forms.Build.Tasks.ModuleDefinitionExtensions.ImportCtorReference(ModuleDefinition module, TypeReference type, TypeReference[] classArguments, Func`2 predicate)
at Xamarin.Forms.Build.Tasks.ModuleDefinitionExtensions.ImportCtorReference(ModuleDefinition module, ValueTuple`3 type, Int32 paramCount)
at Xamarin.Forms.Build.Tasks.XamlCTask.TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, Exception& exception)
Resource: Ils.MainPage.xaml
Creating empty MainPage.__InitComponentRuntime
done.
Copying body of InitializeComponent to __InitComponentRuntime
done.
Parsing Xaml
done.
Replacing 0.InitializeComponent ()
failed.
MainPage.xaml : error : Value cannot be null.
MainPage.xaml : error : Parameter name: type
at Mono.Cecil.Mixin.CheckType(Object type)
at Mono.Cecil.ModuleDefinition.ImportReference(TypeReference type, IGenericParameterProvider context)
at Xamarin.Forms.Build.Tasks.ModuleDefinitionExtensions.ImportCtorReference(ModuleDefinition module, TypeReference type, TypeReference[] classArguments, Func`2 predicate)
at Xamarin.Forms.Build.Tasks.ModuleDefinitionExtensions.ImportCtorReference(ModuleDefinition module, ValueTuple`3 type, Int32 paramCount)
at Xamarin.Forms.Build.Tasks.XamlCTask.TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, Exception& exception)
Changing the module MVID
done.
Writing the assembly
done.
Done executing task "XamlCTask" -- FAILED.
Done building target "XamlC" in project "Ils.csproj" -- FAILED.
@jpajak @JasonBro please provide (one each) a small project triggering this issue. Without a repro, we'll have to close this ticket again in a few days. Thanks for your time
Thanks for your reply @StephaneDelcroix,
I've tried to repeat it with the project, but it seems to have got itself out of the failure state. As I mentioned, it was a simple project created by the Wizard, so nothing fancy going on.
In both cases it seems to be something to do with XamlCompilation and a failure in replacing InitializeComponent. Could some more logging be put when it fails in so that when it happens again more information can be logged?
Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!
This is still an issue for me (using xf 4 and VS 16.1.2), to someone reproduce is simple, just switch between branches of a project that alternates PCL and NetStandard.
I too am having this issue.
VS community for Mac Version 8.1.1 (build 27)
we have this issue too see https://github.com/xamarin/Xamarin.Forms/issues/5416
I have the same issue after updating to the latest version XF 4.1.0.618606. Now I can solve it with removing all [XamlCompilation(XamlCompilationOptions.Compile)] attributes in every xaml.cs file and [assembly: XamlCompilation(XamlCompilationOptions.Compile)] in the Assembly.cs file.
I just have it in UWP after switching from master to 4.0.0 branch.
I used git command to cleanup all the old remaining files in bin/obj.
git clean -dfx
After that, rebuild from scratch, no more error.
So it's likely an issue caused by some dll mismatch somewhere.
A full project bin/obj cleanup is likely to fix it for others too.
I am facing the same issue after update visual studio in mac. My project was working before update VS. Even I am not able to restore or update Nuget packages also.
Visual Studio Community 2019 for Mac
Version 8.2.2 (build 21).
I have tried below solution but no luck.
Error
Value cannot be null or empty string.
Parameter name: username
No more details found.
@Raj123-S your issue is different. please open a new ticket, make sure you attach a repro case. thanks
or...
it's is very unlikely that this exception comes from XF code (I can't think of any method taking username
as a parameter), and investigate which method of yours, or your dependency, that can throw this ArgumentException.
Thanks Stphene,
I have created a new ticket for this issue
https://github.com/xamarin/Xamarin.Forms/issues/7138
Facing the same issue on
Microsoft Visual Studio Enterprise 2017
Version 15.9.14
VisualStudio.15.Release/15.9.14+28307.770
Microsoft .NET Framework
Version 4.8.03752
Xamarin 4.12.3.83 (d15-9@23fa80172)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 4.16.30 (e0af99a34)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 1.1.128 (6f5ebb2)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 9.1.7.0 (HEAD/ba9da7a76)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK 12.4.0.64 (9c8d8e0)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
The error come up building the forms project
it comes up almost randomly though. seems to disappear on clear/rebuild
Hi @shehrozeee
In project root directory, there is one hidden folder ".nuget" in that you can see config file.
Open this config file and remove below lines with parent tag.
Thanks @Raj123-S , It seems to be working again now. I will try your suggestion if it stops working again.
I have the same issue after updating to the latest version XF 4.1.0.618606. Now I can solve it with removing all [XamlCompilation(XamlCompilationOptions.Compile)] attributes in every xaml.cs file and [assembly: XamlCompilation(XamlCompilationOptions.Compile)] in the Assembly.cs file.
Thanks , this worked for me.
removing [assembly: XamlCompilation(XamlCompilationOptions.Compile)] in the Assembly.cs file.
This workaround above worked for me ^ thanks
@StephaneDelcroix do you still want a repro?
I am also facing this error after updating to Xamarin Forms 4.3 and using VS2017.
_Error: Value cannot be null. Parameter name : key_
Do we have a fix for this instead of workarounds like commenting out xamlcompilation?
Thanks
Seeing this with the attached VS environment and project using Xamarin Forms 4.5.0.356.
Getting rid of [assembly: XamlCompilation(XamlCompilationOptions.Compile)] works around the problem.
In case this helps anyone:
I had this same issue under VS 2019; clean and rebuild did nothing, however I remembered I had done a recent Nuget package update, and realized this was caused by a mismatch of Xamarin.Forms versions between the platform specific projects and the shared .Net library.
Updating both to the same version resolved the error spew.
@knocte
@StephaneDelcroix do you still want a repro?
if you can reproduce this in a clean new solution, please open a new ticket
Same thing. I had to comment out
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
in AssemblyInfo.cs, as well as
[XamlCompilation(XamlCompilationOptions.Compile)]
in the codebehind for the offending ContentPage. There is absolutely nothing wrong with the XAML and the same source code compiles fine in the Master branch. This did happen (to one and only one ContentPage) after updating XF this morning to the latest.
@suchithm I did not have to remove the XamlCompilation
line from _every_ codebehind, just the one for which the XAML was generating the error.
Edit #2: the workaround above allowed the code to compile, but it would not run (generated an exception). The workaround that worked for me was delete the XAML and CS files for that specific view, add them as "new" files with the same name, then paste the guts of the original files back into the new files. Now it builds and runs just fine, again.
I've seen this happen before, too, when updating projects. Usually, closing Visual Studio and restarting will resolve it. When the issue is persistent, it usually means that there is some binding or syntax error that is too egregious for the XAML parser to handle (like a circular binding, missing or changed API, etc.). If the restart doesn't fix it, disable XAMLC and then make sure you pay close attention to the debug output to see if any binding errors are reported. If you're STILL unable to figure out what's causing the issue, please try to create a reproduction for us! Thanks!!!!
@samhouts I was able to recreate the exact error by creating a new, blank "shell" app (with Android and iOS projects) and then trying to build the new, vanilla project without making any changes. If you want me to package it somehow for you, ping me offline and let me know how.
VS 2019 16.4.5
XF 4.3.0.908675
PS: I was not connected to my Mac at the time, so ignore the iOS build hiccup - my mainline project is always connected to my Mac, same effect.
These are the kind of bugs that should get top priority as they completely kill the workflow and waste an incredible amount of time.
hello i still have the same issue anyone to help ?
So do I on 4.6.0.847
Hello, I have the same problem. I copied the code in a notepad and went through each of the elements that made up my Xaml file and I was trying to compile it. Then I realized that I had left a Binding with no content between the quotes ("") in a component. I deleted that part and the code worked again.
It is my experience. I hope to be of help.
Regards!.
I can confirm that this typically happens when you have some kind of unsupported construct in your XAML. A recent example of mine was that I created a new Xamarin Forms project and started using the new 4.7 (wonderful) feature of short hand Grid ColumnDefinitions
and RowDefinitions
, i.e. <Grid ColumnDefinitions="0.5*, 0.5*" RowDefinitions="Auto, Auto, Auto" ...>
After an hour of frustration looking at the "Value cannot be null. Parameter name: key" in Line 1 (!) error, restarting VS, cleaning the solution, etc. etc., I found this issue and - after a while - realized that the project template used Xmarin.Forms 4.6. Upgrading to 4.8 of course made everything fine again.
So to avoid such waste of precious development time, hopefully there is somewhere in your XAML parsing that can benefit from better error handling in these cases, so it at least could point me to the correct line of XAML, and preferably with a more precise error message too. But just the line number would be a huge improvement in these cases.
Anyway, here you also have a very specific and easy way of recreating the issue.
we had this issue with a custom web view renderer, our renderer was inheriting IUIWebViewDelegate
, removing that resolved it for us.
I don't know how to reproduce but I can confirm it is still happening under sample solution with XF 5.0.0-Pre2.
there is somewhere in your XAML parsing that can benefit from better error handling in these cases, so it at least could point me to the correct line of XAML, and preferably with a more precise error message too.
we're doing just that every time we get a report, with an attached repro.
the original issue has been fixed, open a new ticket, with repro, for any other case when the xaml parser throws a generic exception instead of a specific one.
Most helpful comment
I can confirm that this typically happens when you have some kind of unsupported construct in your XAML. A recent example of mine was that I created a new Xamarin Forms project and started using the new 4.7 (wonderful) feature of short hand Grid
ColumnDefinitions
andRowDefinitions
, i.e.<Grid ColumnDefinitions="0.5*, 0.5*" RowDefinitions="Auto, Auto, Auto" ...>
After an hour of frustration looking at the "Value cannot be null. Parameter name: key" in Line 1 (!) error, restarting VS, cleaning the solution, etc. etc., I found this issue and - after a while - realized that the project template used Xmarin.Forms 4.6. Upgrading to 4.8 of course made everything fine again.
So to avoid such waste of precious development time, hopefully there is somewhere in your XAML parsing that can benefit from better error handling in these cases, so it at least could point me to the correct line of XAML, and preferably with a more precise error message too. But just the line number would be a huge improvement in these cases.
Anyway, here you also have a very specific and easy way of recreating the issue.