Bengi Besceli
Bengi Besceli

Reputation: 3748

InitializeComponent does not exist

InitializeComponent();

This code line appeared in all my Xaml pages' constructors in code behind. It throws the following error:

InitializeComponent does not exist.

Now I cannot debug any page in my project although I have commented out this line.

How can I fix this?

Any help would be greatly appreciated.

Note: I'm using Xamarin Forms Portable project.

Update: When I comment out this line and run the pages, only an empty screen shows up in both IOS and Android although my pages were working correctly without error before.

Update 2: now the InitializeComponent lines are disappeared but the pages that I debug are still totally blank.

I have asked a question about this new problem on here.

Upvotes: 3

Views: 3756

Answers (9)

vaindil
vaindil

Reputation: 7854

I had this problem because the namespace of my .xaml file did not match the namespace of the .xaml.cs file. Fixing the namespaces so they matched corrected the problem.

Upvotes: 0

drchilds
drchilds

Reputation: 51

In my case this was a result of intermediate build paths being too long for Windows. Moving my solution to just off the drive root C:\dev{solution} in my case solved the problem.

Upvotes: 0

Mohamed Ibrahim Elsayed
Mohamed Ibrahim Elsayed

Reputation: 2964

Is it the first XAML page you create in the project? or you created other pages and they don't contain this problem? you can Check the comments here: http://forums.xamarin.com/discussion/17638/initializecomponent-does-not-exist/p4

Upvotes: 1

Ranjithkumar
Ranjithkumar

Reputation: 18386

Simple trick:

Just edit your Xaml code..(Put space also enough..But need editing)

After edit the xaml page save project..

Now check error disappears..

Upvotes: 0

Ravindra Kumar
Ravindra Kumar

Reputation: 601

I had also the same problem in Xamarin Forms Application.I fixed it by changing the Build Action to:

Embedded resource

for .xaml and .cs file both using property window.

enter image description here

Hope it may help you.

Upvotes: 9

Arnab Kundu
Arnab Kundu

Reputation: 1527

'Its not an issue. You can try to build your solution. Hopefully it will bulid perfectly. Most of the time I also get red under line on InitializeComponent(); like you same. Its a problem of Xamarin studio and Visual studio'

Upvotes: 1

George Papadakis
George Papadakis

Reputation: 1368

Be sure that your Xaml page has property Custom Tool set to MSBuild:UpdateDesignTimeXaml

enter image description here

Upvotes: 4

Joe Healy
Joe Healy

Reputation: 5817

Change something in the page, then save it. Scarily this resolves the issue sometime.

If that doesn't work. Update your nugget packages so Xam Forms is the latest. "Clean" your project Go to your project dir and delete the bin and obj from your projects via File Explorer.

Rebuild it.

Good luck.

Upvotes: 7

Geek Josh
Geek Josh

Reputation: 393

Have you renamed your page? All XAML pages have a viewable partial class (the one you enter your logic code in to) and a hidden, system generated partial class.

If you renamed the class but did not use the VS rename macro, your system generated partial class no longer matches your editable partial class.

Try running 'Clean Solution' and 'Rebuild Solution' (both in the 'Build' menu) to see if VS can automatically detect and fix this for you.

If that doesn't work, make sure your pages are set as partial classes e.g. public partial class MyPage : Page

If you still have no luck, manually delete the 'obj' folder in your project's root folder, then rebuild again.

Upvotes: 0

Related Questions