I will sometimes get a red error that says:
InitializeComponent does not exist in the current context
Along with the other variables that I have in my .xaml
that are bound by x:Name
. The x:Class
in the Xaml file does correspond to the namespace and class name in my xaml.cs
file.
The build action for my xaml file is set to "Embedded Resource" and the build action for my xaml.cs
file is set to "Compile". The error only appears randomly and the project runs like normal even with the red errors. I am developing on windows 8.1 with Visual Studio with Xamarin.
Even though the code runs, I would like to not see those errors appear. Is there any reason why this is happening?
This helped me:
In package manager console, issue the following command:
update-package -project your_pcl_project_name -reinstall
https://social.msdn.microsoft.com/Forums/en-US/e6d4e336-b3b6-45ef-b681-87c351f902e9/xamarin-forms-project-xaml-compilation-error-in-vs15-community-with-update-2-installed?forum=visualstudiogeneral#answers
If you're using shared project you can't make those "errors" disappear. SAP does not recognize the InitializeComponent() method, so it marks it as an error, because of that the code behind does not recognize the x:Name till you run it.
EDIT 08/11/2015
PCL shouldn't be giving you this kinds of errors, check that your xaml namespace x:Class and your xaml.cs (code behind) namespace is the same.
Another thing you can do is to update your Xamarin.Forms reference to the latest (pre-release included).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With