Bug 33181 - InitializeComponent() method call in XAML code behind page constructor "does not exist in current context" (IntelliSense error)
Summary: InitializeComponent() method call in XAML code behind page constructor "does ...
Status: CLOSED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.5.2
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 30379 32625 40308 (view as bug list)
Depends on:
Blocks: 32988
  Show dependency tree
 
Reported: 2015-08-17 21:15 UTC by Jon Goldberger [MSFT]
Modified: 2017-06-28 19:19 UTC (History)
57 users (show)

Tags: BZRXF1.4.4.6392_1.4.3.6376
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
CLOSED FIXED

Description Jon Goldberger [MSFT] 2015-08-17 21:15:54 UTC
## Description

With a brand new Forms Portable template project created in Visual Studio 2015 Community Edition, after updating to Forms 1.4.4 in all projects and then adding a new XAML page to the PCL project, the InitializeComponent() method call in XAML code behind page constructor is underlined in red with message "The name InitializeComponent does not exist in the current context."
However the project does build and deploy to iOS, Android, and WinPhone.

In the past this error has been resolved by cleaning/rebuilding and/or closing opening the solution. IN this case, these actions do not resolve the issue but adding an x:Name property to a control in the XAML file does resolve the issue, 

My simple environment: (More detail below) Windows 8.1 on a dedicated PC running VS 2015 Community (fresh install a couple of days ago)

## Steps to reproduce

1. Open VS 2015 community edition and create a new Xamarin Forms Portable project.

2. Update to Xamarin Forms 1.4.4

3. Add a new XAML Content Page to the PCL project

4. Open the xaml.cs code behind file

Expected result: InitializeComponent() will not be underlined in red and no message about not existing in current context will be displayed.

Actual result: InitializeComponent() is underlined in red with message "The name InitializeComponent does not exist in the current context."

5. Now open the XAML file and add an x:Name property to the label. e.g.:
 <Label x:Name="mylabel"   ... />

6. Go back to the code behind page. The red underlining should be gone and no more error message about not exiting in current context. 

## Notes

I added and removed the x:Name property from the XAML page's Label a few times and the issue followed with each change. Also note again that all of the app projects could build and be deployed without error. 

And then all of the sudden the issue disappeared for me. When I launched the Android project to the XAP, I was prompted to disable Hyper-V, which I did not do right away, but after disabling Hyper-v and restarting Windows, the issue no longer occurred. Likely unrelated but thought I would mention it. 


## My environment

Microsoft Visual Studio Community 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00081

Installed Version: Community

Visual Basic 2015   00322-20000-00000-AA593
Microsoft Visual Basic 2015

Visual C# 2015   00322-20000-00000-AA593
Microsoft Visual C# 2015

Visual C++ 2015   00322-20000-00000-AA593
Microsoft Visual C++ 2015

Visual F# 2015 RC   00322-20000-00000-AA593
Microsoft Visual F# 2015 RC

Windows Phone SDK 8.0 - ENU   00322-20000-00000-AA593
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   14.0.20626.0
ASP.NET and Web Tools

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GenerateUnitTest   1.0
Generates unit test code for methods in classes under test.

GitHub.VisualStudio   1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

NuGet Package Manager   3.0.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

Visual C++ for Cross Platform Mobile Development   1.0
Visual C++ for Cross Platform Mobile Development

Visual C++ for Cross Platform Mobile Development   1.0
Visual C++ for Cross Platform Mobile Development

Visual Studio Tools for Universal Windows Apps   14.0.23121.00 D14OOB
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   3.11.836.0 (ed5c750)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.5.3 (f98871a95a479f6d71b3067b7e5834d41fcb2118)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.10.4.0 (6db87c53c073f4af2f5247fb738a27ea08c094fd)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration
Comment 1 Jon Goldberger [MSFT] 2015-08-17 21:29:53 UTC
Update:

Issue reappeared after I built for the Android emulator (and having removed the x:Name property from the Label). Project still builds and deploys though. 

As a further test I added a sec one XAML page to the PCL project and noted that adding the x:Name property to the label in one of the template XAML files resolved the issue on the code behind for both xaml.cs code behind files.
Comment 2 Jon Goldberger [MSFT] 2015-08-17 21:31:46 UTC
^^^^
s/sec one/second
Comment 3 Abhishek 2015-08-18 08:31:46 UTC
I have checked this issue and I am able to reproduce the reported behavior at my end with the following bug description.

Screencast: http://www.screencast.com/t/Hp2ZdFwCoCq
IDE log: https://gist.github.com/Rajneesh360Logica/9ba495e7b3dfb3dbd999

Environment Info:

Xamarin.Forms: 1.5.0.6396-pre1

Microsoft Visual Studio Community 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00079

Installed Version: Community

Visual Basic 2015   00322-20000-00000-AA500
Microsoft Visual Basic 2015

Visual C# 2015   00322-20000-00000-AA500
Microsoft Visual C# 2015

Visual C++ 2015   00322-20000-00000-AA500
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-20000-00000-AA500
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   14.0.20626.0
ASP.NET and Web Tools

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GenerateUnitTest   1.0
Generates unit test code for methods in classes under test.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.0.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

Visual Studio Tools for Universal Windows Apps   14.0.23121.00 D14OOB
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.11.881.0 (0716d53)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.5.3 (f98871a95a479f6d71b3067b7e5834d41fcb2118)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.10.4.0 (2c66d2fed40ae89b785ae3830b9555e4a3687ab7)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration
Comment 4 Russell Fustino 2015-08-28 01:05:31 UTC
It seems the generation of the xaml.c.gs in the obj directory is not being done correctly on a build or they may disappear somehow after a successful build . There are a variety of ways they somehow reappear. Like adding a XAML Forms file to the project.. it will go away temporarily, but then the problem will reoccur when you open the solution the next time. This is really weird behavior indeed. What is the last good build of the VS Xamarin software where this does not happen?  Or is this happening on all builds w vs 2015? If you unload the pcl project when it is working right and reload it, the .gs files are then  missing too. They somehow disappear!
Comment 6 wislon 2015-12-01 03:38:30 UTC
So this is still a thing. And it's brought my work to a grinding halt after an upgrade to Xamarin 4 / Xamarin Forms 2. 

I can sometimes get it to to work in visual studio (2013 Update 4), but xamarin studio is now even more of a total loss. 

Anyone? Any progress?
Comment 7 Chris Towles 2015-12-02 19:40:59 UTC
I've been working around this in Visual Studio 2015 by setting my "Error List" to show "Build only" errors but I would really like my IntelliSense.
Comment 8 Matthew Regul 2015-12-03 20:32:08 UTC
Appears this issues occurs in the latest version of Xamarin Studio as well

Xamarin Studio Version Info - https://gist.github.com/mattregul/78e7fd05840b7bd346aa#file-xamarin-studio-version-info-cs

Visual Studio Version Info - https://gist.github.com/mattregul/78e7fd05840b7bd346aa#file-visual-studio-version-info-cs

(See private note for more details)

==== Related Bug Report ====
Xamarin Studio version of this bug - #30379
Comment 9 Matthew Regul 2015-12-03 20:33:00 UTC
==== Related Bug Report ====
Xamarin Studio version of this bug - https://bugzilla.xamarin.com/show_bug.cgi?id=30379

( apparently just doing #<number> doesn't auto link to that bug report :] )
Comment 11 Shawn 2015-12-05 14:05:45 UTC
4 months and still no fix?
Comment 12 Mike Rowley 2015-12-05 16:43:42 UTC
I highly suggest emailing support requesting a status update for this bug.  Support eluded to not prioritizing bugs if they don't know they are having impact on users, apparently posting here or in forums is not enough.

Here is the link to my comment including Xamarin's support response.
https://forums.xamarin.com/discussion/comment/166799/#Comment_166799

Anyone having this issue, please email support asking for status so they know the bug is having a major impact on your development so we might be able to finally get a fix.

Thanks
M
Comment 13 Pete Vickers 2015-12-09 15:21:32 UTC
Come on guys - as other people have commented - 4 months!!
This adds to my working day, and impacts my performance, spending time trying to sort the wheat from the chaff.
This is causing lots of your users lots of hassle.
Please ask Santa to fix it ASAP - Please!
Comment 14 Bo Visfeldt 2015-12-11 08:29:33 UTC
Wrote to Xamarin support, and got the reply that the issue was elevated and the engineering team is on it right now.
Comment 15 Brendan Zagaeski (Xamarin Team, assistant) 2015-12-15 00:48:06 UTC
This bug seems very closely related to Bug 32988. In particular, the two problems are complementary: saving a change in the XAML file _stops_ Bug 33181, but _causes_ Bug 32988.




## Regression status: regression between 1.4.3 and 1.4.4

BAD:  XF 1.4.4.6392
GOOD: XF 1.4.3.6376




## Possible partial workaround for VS 2015 Update 1 users

For any users running VS 2015 Update 1, there is a chance that switching to using VS 2015 Update 1's built-in Xamarin.Forms IntelliSense [1] might help.

[1] https://visualstudiogallery.msdn.microsoft.com/8195a8e2-a842-4389-a8cb-34e4672e2e13
Comment 16 Brendan Zagaeski (Xamarin Team, assistant) 2015-12-15 01:03:56 UTC
*** Bug 32625 has been marked as a duplicate of this bug. ***
Comment 17 Shawn 2016-01-04 19:41:50 UTC
Is there any chance of this being fixed in the near future?  It is really slowing down productivity as we need to sift through hundreds of "fake errors" to find the real ones.
Comment 18 Dustin Jackson 2016-01-19 19:30:06 UTC
My team just purchased a business license and we are experiencing this issue with Xamarin Forms 2 and Visual Studio 2015.  The work-around posted above did not help...

Can someone from Xamarin provide an update?  In its current state this bug is impacting productivity quite severely to a point where Visual Studio is basically unusable.
Comment 19 Chase Florell 2016-01-20 17:40:13 UTC
Seeing this issue also after switching to VS 2015.

Microsoft Visual Studio Enterprise 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Enterprise

Architecture and Modeling Tools   00322-80000-00000-AA414
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

Visual Basic 2015   00322-80000-00000-AA414
Microsoft Visual Basic 2015

Visual C# 2015   00322-80000-00000-AA414
Microsoft Visual C# 2015

Visual C++ 2015   00322-80000-00000-AA414
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-80000-00000-AA414
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8)   14.1.11106.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JetBrains ReSharper Ultimate 10.0.2   Build 104.0.20151218.120627
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2016 JetBrains, Inc.

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

NuGet Package Manager   3.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

TypeScript   1.7.4.0
TypeScript for Microsoft Visual Studio

Visual Studio Tools for Universal Windows Apps   14.0.24720.00
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   4.0.0.1717 (1390b70)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.0.35 (d300845)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.3.99.33 (ea30b32)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 20 Matthew Regul 2016-01-21 19:32:24 UTC
While it might not be the solution, please ensure that your troublesome XAML file's "Build Action" is set properly.

I observed a case today that was receiving this error, it turned out that Build Action was set to "None" for the XAML file, when it should have been "EmbeddedResource"

After switching the action, the issue disappeared. 

==============
Build Action's should be...
XAML file's Build Action = EmbeddedResource
XAML.CS's   Build Action = Compile
Screenshot
https://cloud.githubusercontent.com/assets/8008527/12491857/3a8d3114-c04b-11e5-88bc-ce3ee9e90a6c.png
Comment 21 Brendan Zagaeski (Xamarin Team, assistant) 2016-01-21 19:41:30 UTC
## Clarification on Comment 20 for customers CC'd on the bug

Comment 20 shows a screenshot for Xamarin Studio. This bug is about Visual Studio.

While the build action of the XAML files is important, it is unlikely to be the cause of the problem for most of the customers on this bug report.

In short, feel free to disregard Comment 20.
Comment 22 Mikayla Hutchinson [MSFT] 2016-01-21 23:53:42 UTC
We've been able to reproduce this and we're currently working on a fix. In the meantime, you can work around the issue by replacing the contents of the  Xamarin.Forms.targets file in the packages directory with the contents of https://gist.github.com/jassmith/12da211f27f212651e14
Comment 23 Jason Smith [MSFT] 2016-01-22 10:53:57 UTC
Just FYI that wont work with Shared Projects, you will probably get build failures
Comment 24 Dustin Jackson 2016-01-22 15:32:31 UTC
Replacing the Xamarin.Forms.targets file with the version post by @mhutch has temporarily resolved the issue for me (I am using PCL).

I look forward to the next update, Thank you all!
Comment 25 Dustin Jackson 2016-01-22 21:34:45 UTC
Just an update to my previous comment, it seems as if the work around only half fixes the problem.

The new Xamarin.Forms.targets file fixed the intellisense error for InitializeComponent(), however after I build/stop the project, references to my other assemblies "break" (i.e. they incorrectly become underlined as invalid).

Also, the update to the targets file breaks the build in Xamarin Studio so now both environments have issues.  

We are paying a significant amount of money for the Visual Studio Integration and we are currently unable to use it.  Can you please let us know when this issue will be fixed.  This issue has been present for several months which is concerning.
Comment 26 Jason Smith [MSFT] 2016-01-23 10:16:47 UTC
We're working on, Roslyn has changed a lot about how generated files are picked up and it is a non-trivial thing to fix. Worse there are incompatibilities with how Roslyn and XS work. Getting something to work on XS VS 2012/13/15 all at once may not even be fully possible right now without heavy conditioning.

To mitigate this effect of the issue I suggest the following actions while we continue to work for a solution:

1) Change your errors pane from Build + Intellisense to Build Only
2) If you use Resharper go into the excluded file mask and add *.xaml.cs

This will make it so the IDE doesn't report a huge list of errors to you when building and will ensure resharper shows you a clean status.
Comment 27 Michael Rumpler 2016-01-31 14:47:05 UTC
Hm? I do have several elements in my XAML with x:Name attributes, but VS still doesn't know the InitializeComponent() method in the code behind. What's worse, it also doesn't know the elements where I set x:Name and I therefore don't get intellisense for those objects.
Comment 28 Logic Mate 2016-02-01 19:37:39 UTC
We used Shared Project with XAML and have the same issue.  would the fix on Comment 22 work for us? We are using latest version of Xamarin with VS2015.

Thanks
Comment 29 Jason 2016-02-17 01:45:51 UTC
No word in 2 weeks - any updates on this? Has someone found a workaround maybe (and thus the silence)?
Comment 30 Joaquin Jares 2016-02-17 12:22:16 UTC
I have fixed the remaining errors in the templates. The change will be available (probably) in the next release of XamarinVS.

There where two remaining issues, with simple workarounds:
1. The UWP is missing a nuget package. Adding "Microsoft.NETCore.UniversalWindowsPlatform" will make the weird "Can't find System.Object" errors go away.
2. The references to the PCL are missing information needed by VS to properly compile them for intellisense. That is what produces the "Class App not found. Are you missing a reference or namespace?" type errors. The simple workaround is to remove and re-add the references from the App projects to the PCL.

There is also an Android error that is not related but may happen. That error ends up in about 1000 errors in the Android project. The simple solution to that is to install API Level 23 from the SDK manager. Unloading and reloading the Android app project may be needed.

I'm closing this as resolved for testing and verification.
Comment 31 Victor Arce 2016-02-17 18:18:35 UTC
@Joaquin Jares thanks for sorting this out. Let us know when its in Alpha so we can test it also.
Comment 32 Viktorija Krapaviciute 2016-03-04 14:48:10 UTC
I also have this problem, but going to version 1.4.3.6376 or lower helps me to develop for a time being. Have you tried this?
Comment 33 Viktorija Krapaviciute 2016-03-04 15:20:56 UTC
Also it seems like it can be related with UWP, because this error does not occur (and dependencies stays as they supposed to) when  building Xamarin.Forms Android or iOS project.
Comment 34 Viktorija Krapaviciute 2016-03-04 15:41:15 UTC
No it is nothing to do with UWP, the error occurred again after a while.
Comment 37 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-23 06:28:00 UTC
Upon further study it seems the issue as originally described in Comment 0 is somewhat different from the problem discussed in Comment 30. (I believe Comment 30 only applies to UWP projects.)




## Steps to replicate

The exact original steps to replicate as listed in Comment 0 will _not_ show the problem because the `XamlG` task does run once when you first add the `.xaml` file at step 3. But if you delete the `obj\` folder and then close and reopen the solution, you will then be able to replicate the problem as described: no amount of cleaning, rebuilding, or closing and reopening the solution will stop the IntelliSense error.




## Associated commits

This issue was introduced by the following commit:

0bb8c1e707273043ca522970bf206bb12a1c10d3 (Bug 29501)

That commit replaced `CompileDependsOn` with `PrepareResourcesDependsOn` in the following lines of `Xamarin.Forms.targets`:

> <CompileDependsOn>
> 	XamlG;
> 	$(CompileDependsOn);
> </CompileDependsOn>


The switch from `CompileDependsOn` to `PrepareResourcesDependsOn` changed the timing of _when_ the `.g.cs` file is generated and registered by IntelliSense. With `PrepareResourcesDependsOn`, the `XamlG` task now doesn't run until the user explicitly saves a change to the `.xaml` file.




## Candidate workaround from Comment 22

The candidate workaround in Comment 22 addresses this problem by adding the `XamlG` task to one additional location in the `.targets` file:

> <PropertyGroup>
> 	<CoreCompileDependsOn Condition="'$(BuildingInsideVisualStudio)' == 'true' ">
> 		DesignTimeMarkupCompilation;
> 		$(CoreCompileDependsOn);
> 	</CoreCompileDependsOn>
> </PropertyGroup>
> 
> <Target Name="DesignTimeMarkupCompilation">
> 	<CallTarget Condition="'$(BuildingProject)' != 'true' Or $(DesignTimeBuild) == 'true'" Targets="XamlG" />
> </Target>

These lines run the `XamlG` task during the `CoreCompile` target, using Conditions to define more precisely when the task should run.




## Results after adding this `CoreCompile` workaround to the `Xamarin.Forms.targets` file

Bug 33181 - GOOD (Tested with Xamarin.Forms 1.4.4.6449)
Bug 33181 - GOOD (Tested with Xamarin.Forms 2.1.0.6529)

(For both of these Xamarin.Forms versions I also confirmed that I was able to hit the BAD behavior of Bug 33181 before applying the workaround.)




## Alternate workaround

It turns out there is at least one other way to work around this issue.

See Bug 32988, Comment 18 for the details. One advantage of the alternate workaround is that it also addresses Bug 32988.




## Results with the alternate workaround

Bug 33181 - GOOD (Tested with Xamarin.Forms 1.4.4.6449)
Bug 33181 - GOOD (Tested with Xamarin.Forms 2.1.0.6529)
Comment 38 Victor Arce 2016-03-23 07:41:39 UTC
Hi Brendan, 

great job, I implemented your changes and its FIXED! I can't thank you enough. Bugs 33181 and 32988

It's been a while since I've had this problem, i'm using Xamarin.Forms 2.1.0.6529 and VS 2015 Update 1.

I implemented your changes manually and also from comment 22

And yes, there where two major problems: XAML Intellisense (33181) + Other PCL broken references (32988). The simplest way to reproduce the error was to save the XAML file, and the .CS will start to present errors.

The only odd thing that I bumped into is that I started getting an error when compiling a Droid app, related to XF version 6524 (which I think I never installed)

I just removed "<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.1.0.6524\..." from the CSProj file and everything was set.

Please include both changes in the next release, I'm sure a lot of people, like me, will be grateful.

This is the final Xamarin.Forms.Targets file I compiled, if anyone wants to save some time:

https://gist.github.com/victorarce/8f42ae855457275d1924
Comment 39 Victor Arce 2016-03-23 15:36:28 UTC
I forgot to tell you that you need to restart VS after changing the file in order for this to work.
Comment 40 wislon 2016-03-23 20:59:13 UTC
It works! Thanks so much you guys!

I had to paste the contents of Victor's gist over the contents of my x.f.targets file located in the 

(solution)\packages\Xamarin.Forms.2.0.1.6505\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10

folder (and then restart VS), but it all seems to be behaving itself now.

Thanks again Brendan and Victor! :)
Comment 41 Samantha Houts [MSFT] 2016-04-08 20:05:14 UTC
*** Bug 30379 has been marked as a duplicate of this bug. ***
Comment 42 Chris King 2016-04-13 19:16:25 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
Comment 43 Brendan Zagaeski (Xamarin Team, assistant) 2016-04-13 19:27:24 UTC
## For any users watching this bug report

I am currently working on verifying the candidate fix for this bug (that is included in Xamarin.Forms 2.2.0.5-pre2). There are a few subtleties to achieve the best results when using the new candidate fix. I will be filing a follow-up bug report to discuss a couple of those details. I will add a link to that follow-up bug when it is ready.
Comment 44 Brendan Zagaeski (Xamarin Team, assistant) 2016-04-25 05:52:09 UTC
## Verification status: verified fixed on Xamarin.Forms 2.2.0.5-pre2 and 2.2.0.23-pre4 (available on NuGet)

GOOD: Xamarin.Forms 2.2.0.23-pre4
GOOD: Xamarin.Forms 2.2.0.5-pre2
BAD:  Xamarin.Forms 2.1.0.6529


As hinted at in Comment 43, there is one subtle, fairly uncommon situation where the default behavior for this issue in the "GOOD" versions might still occasionally cause some confusion or inconvenience. I have filed a separate in-depth follow-up bug report about that situation: Bug 40666.
Comment 45 Brendan Zagaeski (Xamarin Team, assistant) 2016-04-25 23:28:54 UTC
*** Bug 40308 has been marked as a duplicate of this bug. ***
Comment 46 Bob Japundza 2016-04-29 16:44:15 UTC
I have been wrestling with this bug for quite sometime and found that I had to edit the .csproj manually and add each existing xaml page in my project as an embedded resource:

<EmbeddedResource Include="Calculator\CalculatorPage.xaml">
     <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>

This entry doesn't get added if one manually changes the property.  But it does get properly added when creating new files in VS2015 Update 2.
Comment 47 James Montemagno [MSFT] 2016-08-30 22:25:41 UTC
I am noticing in VS 2015 Update 4 that when you add a XAML page that the SubType gets added:

<EmbeddedResource Include="View\Page1.xaml">
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
      <SubType>Designer</SubType>
    </EmbeddedResource>

If you remove    <SubType>Designer</SubType> then it seems to work again.
Comment 50 Paul DeCarlo 2016-09-26 22:02:18 UTC
Using the latest Xamarin.Forms Shared Project Template as-is without modification, I encountered "The name InitializeComponent does not exist in the current context." when attempting to build the unmodified UWP project.  I was able to build the UWP project by updating the Xamarin.Forms nugget package to latest stable.
Comment 51 dpedrinha 2016-09-30 06:06:21 UTC
I'm getting this error with the latest Xamarin.Forms 2.3.2.127 (latest stable).

I tried the Xamarin.Forms 2.3.3.152-pre2 and the problem persisted.

I uninstalled Forms, installed Xamarin.Forms 2.3.1.114 and now it compiles without throwing errors, but the initializeComponent and any other reference to the Xaml files are still underlined in red.
Comment 52 Brendan Zagaeski (Xamarin Team, assistant) 2016-09-30 06:13:38 UTC
This exact bug report can be considered closed at this time.  Further discussion of similar symptoms will be discussed on other new bug reports.

For example, there is at least one open report of the same IntelliSense error that is in progress: Bug 43835.
Comment 53 Rob Wilson 2017-06-28 19:19:54 UTC
I've just experienced this option with Visual Studio 2017, I had deleted by obj and bin folders and packages (nuget) to try and flush out a different issue.

The only way I could get past this was to right-click on each XAML file list, choose properties, then change the build action to 'content' then back to 'Embedded Resource'.

I don't know why, but that's the only thing that worked for me - am I not able to safely delete those folders?

Hopefully this comment helps someone else.

Regards,
Rob.


Microsoft Visual Studio Community 2017 
Version 15.2 (26430.14) Release
VisualStudio.15.Release/15.2.0+26430.14
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Community

Visual Basic 2017   00369-60000-00001-AA655
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA655
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA655
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA655
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.6.00404.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30503.0
ASP.NET and Web Tools 2017

ASP.NET Web Frameworks and Tools 2017   5.2.50303.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.2.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Dotfuscator Community Edition   5.27.0.4679-release+ce-vs15.e4937ba.20161216.158
PreEmptive Protection - Dotfuscator CE

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Hive Query Language Service   2.2.5000.0
Language service for Hive query

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50131.1

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools   15.1.61702.140
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript   2.2.2.0
TypeScript tools for Visual Studio

Visual Studio Tools for Apache Cordova   15.113.6201.1
Visual Studio Tools for Apache Cordova

Visual Studio tools for CMake   1.0
Visual Studio tools for CMake

Visual Studio Tools for Universal Windows Apps   15.0.26430.06
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   4.5.0.486 (fec6f88)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.3.1.2 (9dbc4c5)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.10.0.37 (ad35de4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.