Forum Xamarin.Forms

Xamarin Forms iOS error: CS0103 The name 'InitializeComponent' does not exist in the current context

rvrezinirvrezini BRMember

Hello, I'm using Xamarin Forms for develop Android and iOS app. My app it's working in Android, but when i compile the iOS version (project) the error "CS0103 The name 'InitializeComponent' does not exist in the current context" appears. I'm updated the Forms nugget package, but not happens and the error occurs every time. Can anyone help me?

Best Answer

  • rvrezinirvrezini BRMember
    Accepted Answer

    Thank you for your help. I solved it by creating a new iOS project and adding it to my solution.

Answers

  • RavinderJangraRavinderJangra USMember ✭✭✭

    Did u rename the file or something. Or use should try to rebuild or clean and build.

  • rvrezinirvrezini BRMember
    edited July 2017

    Hi RavinderJangra, I did not rename the file. I already tried to rebuild and clean.

    This is my App.xaml.cs file:

    using System;
    using Havan.Mobile.Favoritos.Views;
    
    using Xamarin.Forms;
    using Havan.Mobile.Favoritos.Model;
    using Havan.Mobile.Favoritos.Services;
    using System.Threading.Tasks;
    using System.Text;
    using System.Collections.Generic;
    using Newtonsoft.Json;
    using System.Net;
    
    namespace Havan.Mobile.Favoritos
    {
        public partial class App : Application
        {
    
            public App()
            {
                InitializeComponent();
    
                MainPage = new MainPage(false);
            }
    
            protected override void OnStart()
            {
                //ClearData();
            }
    
            protected override void OnSleep()
            {
                // Handle when your app sleeps
            }
    
            protected override void OnResume()
            {
                // Handle when your app resumes
            }
        }
    }
    
    

    And this is my XAML

    <?xml version="1.0" encoding="utf-8"?>
    <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Havan.Mobile.Favoritos.App">
      <Application.Resources>
            <ResourceDictionary>
                <Color x:Key="backgroundColor">#003366</Color>
                <Color x:Key="foregroundColor">#ffffff</Color>
                <Color x:Key="botaoGeralBackgroundColor">#003366</Color>
                <Color x:Key="botaoGeralTextColor">#ffffff</Color>
                <Style x:Key="estiloBotaoGeral" TargetType="Button">
                    <Setter Property="TextColor" Value="{StaticResource botaoGeralTextColor}" />
                    <Setter Property="BackgroundColor" Value="{StaticResource botaoGeralBackgroundColor}" />
                </Style>
                <Color x:Key="LoginTextColor">#003366</Color>
                <Color x:Key="LoginBackgroundColor">#ffffff</Color>
                <Style x:Key="estiloBotaoLogin" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="{StaticResource LoginTextColor}" />
                    <Setter Property="TextColor" Value="{StaticResource LoginBackgroundColor}" />
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    
    
  • RavinderJangraRavinderJangra USMember ✭✭✭

    For which file it is showing the error. Cause it is not showing error line(red underline) for the error in image. and file name is also not visible from error window too

  • rvrezinirvrezini BRMember

    This is the problem, no error appears with the red line in the file. Only the error in the error panel. When I left the mouse over the code "InitializeComponent ()" of App.xaml.cs that popup appears in the image above.

  • rvrezinirvrezini BRMember
    Accepted Answer

    Thank you for your help. I solved it by creating a new iOS project and adding it to my solution.

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    I have the same problem in my App,xaml.cs after renaming a page... I even deleted the renamed page but still showing the same problem

    Kindly help

  • Did anybody find a solution for this issue as I am facing the same. Thanks

  • AsurAsur USMember ✭✭✭

    Unload and reload the project . That should do the trick

  • DarrenKayDarrenKay GBUniversity ✭✭

    Tried all of the above and no luck, what did work for me was force reinstalling the Xamarin.Forms packages. In package manager console prompt;

    update-package xamarin.forms -reinstall

    It does not update packages, just removes and re-adds

Sign In or Register to comment.