Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting an error on InitializeComponent() on xaml.cs files

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?

like image 583
Kevin Guevara Avatar asked Dec 19 '22 01:12

Kevin Guevara


2 Answers

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

like image 176
bruno.almeida Avatar answered Jan 12 '23 23:01

bruno.almeida


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).

like image 42
Cesar Tomatis Avatar answered Jan 13 '23 00:01

Cesar Tomatis