Xamarin.forms: "CS0103 The name 'InitializeComponent' does not exist in the current context" intellisense error

Created on 30 May 2018  ·  32Comments  ·  Source: xamarin/Xamarin.Forms

Description

UWP app project showing Intellisense error with a new, from template Xamarin.Forms solution using a Shared project type.

Steps to Reproduce

  1. In Visual Studio 2017 15.7.2, create a new Cross Platform Xam.Forms solution with Shared project type for shared code.
  2. Select the UWP app as the startup project.
  3. Open the Errors Pane and select "Build + IntelliSense" or "Intellisense Only" in the dropdown.

Expected Behavior

No errors shown

Actual Behavior

Error CS0103 The name 'InitializeComponent' does not exist in the current context App1.UWP
is shown in the errors pane.

Additional notes

Issue was brought up in this forum post: https://forums.xamarin.com/discussion/comment/332572/#Comment_332572

The first time I tried to reproduce it, I got a build error and the UWP app project build failed, as described in the forum post. Cleaning and rebuilding resolved the build error but the Intellisense error remained only for the UWP app project.

I then tested again, creating a new template project of the same type. This second time there was no build error, but the Intellisense error was shown for all three app platform projects. At some point, after cleaning and rebuilding and selecting the iOS app project as the startup project, the INtellisense error went away for the iOS app project, but remained for Android and UWP.

screen shot 2018-05-29 at 2 59 07 pm

I tried closing and re-opening the solutions as well as closing and re-opening the IDE. At some point the Intellisense errors went away. I closed the IDE and re-opened the second solution I created, opened the properties pages to get some info for the bug report, i.e. target frameworks, and the Intellisense errors went away. Not sure after which specific action they disappeared, but it seems to me this was a dance that should not need to be done.

Basic Information


Version Info
Microsoft Visual Studio Enterprise 2017
Version 15.7.2
VisualStudio.15.Release/15.7.2+27703.2018
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Enterprise

Application Insights Tools for Visual Studio Package 8.12.10405.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.40511.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.7.31476
Provides languages services for ASP.NET Core Razor.

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

Azure App Service Tools v3.0.0 15.0.40424.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.3.3000.2
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 15.0.40424.0
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.3.3000.2
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.8.2-beta6-62916-08. Commit Hash: 2ad4aabc7a9dada097e54e544ebba48ab1c05074
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

Fabric.DiagnosticEvents 1.0
Fabric Diagnostic Events

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

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

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

Microsoft Azure HDInsight Azure Node 2.3.3000.2
HDInsight Node under Azure Node

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

Microsoft Azure Service Fabric Tools for Visual Studio 2.1
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.3.3000.2
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0
Azure Stream Analytics Node under Azure Node

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

Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

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

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio 4.10.5-pre (ab58725)
Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.4.11027.3
Adds support for developing and debugging Node.js apps in Visual Studio

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

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

Snapshot Debugging Extension 1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61804.210
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 15.7.20419.2003
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.8.2-beta6-62916-08. Commit Hash: 2ad4aabc7a9dada097e54e544ebba48ab1c05074
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 56f97a8dd4353d897336941f3e644423b87c794f.
Microsoft Visual F# Tools 10.1 for F# 4.1

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Apache Cordova 15.123.7408.1
Visual Studio Tools for Apache Cordova

Visual Studio Tools for Universal Windows Apps 15.0.27703.2018
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.

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Windows Machine Learning Generator Extension 1.0
Windows Machine Learning Visual Studio Extension Detailed Info

Xamarin 4.10.0.448 (4373404db)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.12.270 (82d750d12)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 8.3.0.19 (HEAD/342b2ce96)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 11.10.1.178 (408d357)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.



  • Last known good version: Don't know
  • IDE: Visual Studio 2017 on Windows
  • Platform Target Frameworks:

    • UWP: 16299 -->

    • Android: Compile with: 8.1 Oreo, Min 4.4 KitKat, Target: 8.1 Oreo

    • iOS: iOS 11, Deployment target 8.0

external-intellisense bug

Most helpful comment

Have anyone of you guys tried opening property window of your XAML file and change Build Action property to "Embedded Resource" and the Custom Tool property to MSBuild:UpdateDesignTimeXaml.

All 32 comments

I'm the original poster.

For me clean and build doesn't work. Also close and open of IDE doesn't work. I get constantly this build error. Same system as above (Win 10, VS 2017 15.7.2).

/cc @mgoertz-msft

Looks like this has come up numerous times. @pierceboggan has even opened a bug for it internally (604510). This problem is unrelated to XAML IntelliSense though. It has more to do with Roslyn and the project system. IntelliSense-only failures like this are often caused by design-time build problems. Here are instructions for investigating those:

  1. Close Visual Studio
  2. Open a Visual Studio Developer Command Prompt
  3. Set environment variable “TraceDesignTime” to true (set TraceDesignTime=true)
  4. Delete .vs directory/.suo file
  5. Restart VS from the command prompt you set the environment variable (devenv)
  6. Open the solution
  7. Look at the designtime build log files in the %temp% folder

Another thing to try is to change the Target Version for the UWP app to "Windows 10, version 1803 (10.0; Build 17134)". This resolved the intellisense error for the UWP app project on my end. (I do not get the build error anymore on new forms shared solutions, I only got that the first time as noted in my initial description).

@mgoertz-msft
Please also note that charlenni is experiencing a build failure with the same error message not just an Intellisense failure, so there may be a bit more going on here. See this forum post: https://forums.xamarin.com/discussion/comment/332646/#Comment_332646

I am getting similar compile time issues for my Android project after upgrading to 15.7.2. Target and Compiled using 8.1 Oreo, Min version Android 4.3. I am then unable to get past my app's splash screen. iOS builds and runs fine.

Upgrading from Xamarin Forms 2.4.0.74863 to 2.5.1.444934 fixed my issues. Going to experiment a bit more. What version of Xamarin Forms are you on jgold6?

I was using the new template Forms solution which uses Xam.Forms 3.0.0.482510 by default. Downgrading to 2.5.1.444934 resolves the issue. I was then able to update back to 3.0.0.482510 and the issue was gone.

Sorry for the late answer. We had a bank holiday.

So, I did what @mgoertz-msft and @jgold6 suggested. Started VS 2017 from developer command prompt, set environmet variable, changed the UWP target to 17134, cleaned the solution, deleted all bin and obj folders in all projects. Than set "Set as StartUp Project" to UWP and started on "Local Machine". Same error. Than I found 4 new files in the %temp% folder. I attach them
here. Perhaps @mgoertz-msft or @pierceboggan could find something helpfull.

Thank you all for your help.

Any news about this? Anyone seeing something special in the log files?

I'm getting crazy. Could not work with Xamarin.Forms anymore.

I'm sorry to hear that this keeps happening to you. The log files show that all design time builds completed successfully so that's not the problem. Let's instead look at where InitializeComponent should have been, and that is under the obj folder for the currently active project context as indicated by the left-most combobox on top of the editor (this is different from the startup project). So for UWP that would be: objx86DebugMainPage.xaml.g.cs

You should have that file and it should have something like this in it amongst other things:

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "2.0.0.0")] private void InitializeComponent() { global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(MainPage)); }

Thank you for your help.

No, I don't have such a file. The folder contains after building
grafik
That's all. It is there under "Release" too.

Sorry, should by: it is also not there for "Release" instead of "Debug".

Interesting. I deleted mine and got it back by building. I had to hide and show the items again to refresh Solution Explorer.
Perhaps it would make sense now to increase the build verbosity to Diagnostic under Tools->Options...->Projects and Solutions->Build and Run and share the output here as there seems to be something wrong with the Xamarin markup compilation.

Yes, very strange.

Here are the diagnostic files.

@mgoertz-msft I looked into the log files, but didn't find anything about the conversion from xaml files to xaml.g.cs files. It seems, that this conversion doesn't take place.

@jassmith What kind of information could I provide?

I was referencing Xamarin.Forms 2.3.4.270, cleaning/rebuilding and/or deleting the Debug folder did not help. I upgraded to 3.0.0.561731, rebuilt and problem went away, Then I undid all changes to project, thus downgrading the reference to Xamarin.Forms back to 2.3.4.270, rebuilt and problem was gone.

Have anyone of you guys tried opening property window of your XAML file and change Build Action property to "Embedded Resource" and the Custom Tool property to MSBuild:UpdateDesignTimeXaml.

Have anyone of you guys tried opening property window of your XAML file and change Build Action property to "Embedded Resource" and the Custom Tool property to MSBuild:UpdateDesignTimeXaml.

I've hit the problem after moving the xaml+cs between projects. It looks like the Custom Tool property got changed from MSBuild:UpdateDesignTimeXaml to MSBuild:Compile. It now works for me with Build Action both as "Embedded Resource" and "Page" with the latter being default.

Hi (i have had similar issues with this - google brought me to this page),
It could be related to these 2 defects :
https://github.com/Microsoft/msbuild/issues/2417
https://github.com/dotnet/project-system/issues/2488
thanks
Mike

@VirtualNomad00 and @ezverev : I did this before, but there wasn't any difference to the behavior before.

@MrMikeJJ : Could be the case, even if this comments are older. But how to change this behavior?

I couldn't work on my project for nearly 4 month on my machine. Same code could be compiled on a Mac without problems. Diagnostic files are uploaded like @mgoertz-msft suggested.

It would be nice, if someone has a good idea, how to solve this problem.

For what it's worth, just had this issue and comparing a new blank Xamarin.Forms project to my existing, CS0103 erroring project, I noticed my App.xaml.cs App class definition was different, like this :
public partial class Application : Xamarin.Forms.Application
instead of :
public partial class App : Application

I changed it back to it's original form and it solved the Intellisense and InitializeComponent() compilation issues...

@fgaudet72: No, that doesn't work. I checked it. Was App : Application. And for me even new Xamarin.Forms projects, even the samllest ones, aren't compiling.

@mgoertz-msft: The log files are my last chance to get this working. If you don't find anything, than I have to buy a new PC, what is the worst case :(

@StephaneDelcroix and @alanmcgovern, could you please loop in someone who knows the Xamarin XAML compiler and can help @charlenni figure out why even new XF projects aren't compiling?

@charlenni please attach a failing project, and diagnostic build docs

@StephaneDelcroix Thank you for your help.

I created a new project (Xamarin.Forms, blank, shared project). I attach this project as App6. Than I opened VS2017 (updated this morning to newest version 15.8.7) and try to build the project for UWP. Get the same "CS0103 The name 'InitializeComponent' does not exist in the current context" error again. The diagnostic build output is here. The system info looks like

Microsoft

Visual Studio Community 2017
Version 15.8.7
VisualStudio.15.Release/15.8.7+28010.2046
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Community

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

Application Insights Tools for Visual Studio Package 8.13.10627.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.8.05085.0
ASP.NET and Web Tools 2017

C# Tools 2.9.0-beta8-63208-01
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

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

JavaScript Language Service 2.0
JavaScript Language Service

JavaScript Project System 2.0
JavaScript Project System

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

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

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

MLGen Package Extension 1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.11.11-pre (8fb558f)
Support for debugging Mono processes with Visual Studio.

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

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

TypeScript Tools 15.8.20822.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.9.0-beta8-63208-01
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 55a3dc3231c95c77f81ee53f7d29152029da7408.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Universal Windows Apps 15.0.28010.2046
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.

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Xamarin 4.11.0.776 (d15-8@1ae9b59d7)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.15.9 (d000f568b)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.116 (9619170)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.0.0.19 (HEAD/a8a3b0ec7)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.0.0.15 (84552a4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

If you like to look onto my computer, than this is possible too.

@charlenni your issue is different than the original one. yours is a compile-time issue, while the original is about an intelisense-reported issue.

it's also probably unique to UWP. I created a new ticket (#4074) for it

While Creating New Project, on the area where it provides to select android, ios or both, there at right side there will be Code Sharing Strategy. On that code sharing strategy select .Net Standard. Then this problem will be solved. Thank You!

@StephaneDelcroix: @jgold6 opened this issue after I reported the problem in the forum. I never talked about an IntelliSense error. I don't see, if this is an IntelliSense or a compile error. I get the same results: the project won't compile. And it is not unique UWP. I have the same problem when compiling for iOS and I assume (have not tested this) with Android.

@M-caves: I don't want to create a new project. I have a open source project, that worked before. But for me it is the fastest way to get this error by creating a new project. And Stephane asked for an example project.

I did not open it as a build issue because I was only able to reproduce the build issue one time, then never again. IN the notes I put in the issue description:

Issue was brought up in this forum post: https://forums.xamarin.com/discussion/comment/332572/#Comment_332572

The first time I tried to reproduce it, I got a build error and the UWP app project build failed, as described in the forum post. Cleaning and rebuilding resolved the build error but the Intellisense error remained only for the UWP app project.

closing this as I opened a new one

The namespace and class names need to match so they are both part of a partial class

namespace XXX
{
///


/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow
{
//...
}
}


Was this page helpful?
0 / 5 - 0 ratings