-
Notifications
You must be signed in to change notification settings - Fork 1.9k
"CS0103 The name 'InitializeComponent' does not exist in the current context" intellisense error #2863
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:
|
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 |
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 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: obj\x86\Debug\MainPage.xaml.g.cs You should have that file and it should have something like this in it amongst other things:
|
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. |
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. |
Possibly another user hitting this: https://forums.xamarin.com/discussion/129077/initializecomponent-does-not-exist-in-the-current-contenxt#latest |
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), |
@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 : I changed it back to it's original form and it solved the Intellisense and |
@fgaudet72: No, that doesn't work. I checked it. Was @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
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:
|
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 { //... } } |
In MainPage.xaml |
get this problem. previously had several "solutions" inside which were either one project or several projects (for example - ' lib/console app/lib' ). by creating an empty "solution" and simply copying and manually rewriting the "universal paths" to the library, I got the following tree /main for several months everything worked well, but at a certain point, when adding one of the object projects to the xaml file in the MainWindow file, the vs environment hung and continuing to work in it showed that there were many errors in the .cs file due to the inability to find "InitializeComponent" and that's it related generated objects regarding this function, the most interesting thing is that in this project there are several "window" files (.xaml + .cs) and automatic connection of the "InitializeComponent" function stopped working for all "window" data, however, in all other projects having wpf type project, everything worked smoothly without problems only after remove the element due to which the problem arose, because it was added with errors.
none of the below helped restart vs. deleting /.vs/ folders inside the solution and inside the project directly opening a solution with a bug (as a single solution with a single project inside) solution by @mgoertz-msft (which allowed the project to return to work)
update 10.03.2023 |
I ran into the same problem a while ago. Sourced from FILE_XXX.sg.cs files with the same name belonging to different projects. Project2- **How did I overcome this problem? I updated the Login.xaml file as LoginView.xaml.** |
same for me updating the file name and refactoring it resolved all problem |
Description
UWP app project showing Intellisense error with a new, from template Xamarin.Forms solution using a Shared project type.
Steps to Reproduce
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.
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.03056Installed 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.
The text was updated successfully, but these errors were encountered: