InitializeComponent does not exist

124»

Answers

  • DonBoxDonBox USMember ✭✭

    @EmanueleSabetta sorry, I think you misread my post. I do not blame XF team members in any way. They are not the decision makers, they are developers. When I said Xamarin doesn't believe in XF I meant decision makers.

  • AppnicityAppnicity USMember ✭✭

    @EmanueleSabetta said:

    @dpedrinha said:
    I have a real feeling that this is not going forward. Old problems are never fixed, we have to rely on workarounds all the time. And to make it worse, every update brings more trouble than fixes.

    Xamarin.Forms is indeed understaffed. If you look at the commits on the official repo, you'll see that just 7 people are working on it. And 7 people are not nearly enough for mantaining a project of such size. There are thousands of bugs, critical unsolved issues, insufficient performances due to early wrong architectural choices that don't scale. So it is very hard to understand why in Xamarin decided to hire just 7 people to work on the XF project.
    The XF project is very popular, and now that is shipped with Visual Studio even more than before. But after a while developers see their enthusiasm plummet because find themself literally drowning in bugs.

    Someone should explain us the rationale behind this lack of commitment and resources in a good project like XF. We pay a lot of money every year for this product. People are getting tired of complaining, and at some point they will leave and never come back. If nothing changes soon, Xamarin is going to shoot itself in the foot.

    Unfortunately, I have to agree with you, I feel myself less and less inclined to use Xamarin.Forms after dealing with this bug for so long now. There are SO many work-arounds that only last for a short time and the bugs keep getting closed only to have them re-opened as a new issue, when it's really been there all along.

  • dpedrinhadpedrinha DEMember ✭✭✭

    So they launch a pre release to fix this problem, and then the next stable version comes with it again. UNBELIEVABLE!

  • MikeRowley403MikeRowley403 CAMember ✭✭✭

    @dpedrinha I am running the most current stable version (4.2.1.64) in Visual Studio and I only see this issue anymore when I clean a project and have *.xaml.cs files open. What seems to happen is the partial class in the *.g.xaml.cs files is deleted with the clean and then recreated with a rebuild.

    While irritating, it is much less consistent than it was in the past and doesn't prevent compilation. Try closing any xaml.cs files that are open and see if these false errors disappear from your Error List.

  • dpedrinhadpedrinha DEMember ✭✭✭

    @MikeRowley403 Thanks for the reply.

    But I tried even deleting the obj folder with Visual Studio and all its tabs closed. Opened VS, clean, build, open file. And the problem persists.

  • dpedrinhadpedrinha DEMember ✭✭✭

    Ok, I tested your approach with a new Project and with a project created yesterday and it worked. But for some reason my oldest project won't work.

    I guess I'll need to create a new project and copy each file...

  • MikeRowley403MikeRowley403 CAMember ✭✭✭

    @dpedrinha have you tried upgrading the Nuget package for XamForms in that old project? What version is it currently using?

    Also double check
    Build Action = Embedded Resource
    Custom Tool = MSBuild:UpdateDesignTimeXaml
    for the files that are preventing compilation.

    The InitializeComponent error has been an issue for me since it started, I believe, but has never prevented compilation, simply a seriously annoying Intellisense issue until around the XamForms 2.1 or 2.2 release.

  • dpedrinhadpedrinha DEMember ✭✭✭

    @MikeRowley403 yes everything is up to date with the stable versions and I checked the file settings too.

    I can't tell you the version right now because I just decided to format my computer (since it's impossible to clean uninstall xamarin). But I had everything updated today.

  • NavidNavidNavidNavid USMember ✭✭

    @ChitoSalano said:
    Changing the view properties to these values works for me.

    Build Action -> Embedded Resource
    Custom Tool -> MSBuild:UpdateDesignTimeXaml

    thanks bro!

  • frankfitzgeraldfrankfitzgerald USMember ✭✭

    Just to summarize a lot of these solutions will work but you don't have to do this on every page that you have. If you have this issue on 12 pages if you switch just one to build action of compile and then back to Build action of UpdateDesignTimeXaml this will reset the build in your project and everything goes back to normal.

    Seems to be something in the project config but have not researched the changes as of yet.

  • danthezdanthez CZMember

    I fixed this problem: right click on xaml file in solution explorer => run custom tool

  • dapugdapug USMember ✭✭

    I've been using Xamarin Forms for a various projects for a couple years. I can sum up my observation of Xamarin in one word: unstable.

    Lately I have been fighting the tool, the builds, the config, the Xamarin bugs, more than actually just writing my code. Very frustrating.

    Here is my latest experience:

    • Using VS 2017 RC, latest
    • File / New Xamarin Forms app
    • VS hangs, had to close and re-open, and surprisingly the projects were actually created.
    • Build. Nope. Can't build. "InitializeComponent does not exist"
    • The suggestion to set App.Xaml as Embedded Resource, and Custom Tool setting don't apply - VS has those settings already set correctly.
    • Unload the UWP project.
    • Build, yep, no prob, iOS and droid builds fine.
    • Re-load the UWP project.
    • Build. It works. WHY? And why not before?

    Unstable. Infuriating. Inexplicable.

    And the story only get's worse when we start doing crazy "off the rails" things, like, I dunno, try and deploy to iOS. I don't even want to get into the issues there.

    sigh...

  • wagonzalezwagonzalez COMember

    Porque me sale un error en visual estudio 2017 apenas compilo un nuevo proyecto en xamarin sin realizar ningún cambio en el proyecto

  • DhruvMehrotraDhruvMehrotra USMember

    In VS 2017 when trying to add a page in shared project instead of using User Control use Forms Blank Content Page Xaml template.

  • RogerEdwardSurmayRogerEdwardSurmay USMember ✭✭

    @CraigDunn said:
    If you are moving a .xaml and .xaml.cs file, check:

    • the namespace in the .xaml file matches the new project (the namespace will almost certainly need to be updated), eg
         x:Class="AppNamespace.SomePage">
    
    • the namespace in the .xaml.cs should match too (also, ensure you haven't accidentally removed the partial declaration):
        namespace AppNamespace
        {
            public partial class SomePage : ContentPage
            {
    
    • when you Build the solution the .xaml.g.cs file should be generated in the /obj/ folder. verify it exists, and that the namespace and classname match what you expect (and that an InitializeComponent method is declared).

    If all those things are correct and done, your XAML and code-behind should work.

    This was ahuge help for me. And I realised, when you add some files to a FOLDER, visual studio extends the namespace.

    i.e:

    app1.
    -viewModel
    -views. >>>>>>> new item > anyfile. > "myPage"
    app.cs

    the problem coming here:

    MyPage.cs will has

        namespace App1.view.MyPage //Here is the problem
        {
            public class MyPage
            {
            }
        }
    

    Mypage.xaml

    x:class="App1.Views.MyPage"
    assembly="App1.Views.MyPage" //Error

    Be CAREFUL with namespace name when you add some file into some folder.

    Hope helps.

  • I found the solution:
    for some reason, visual studio is writing some data in .suo file which is stooping the custom tools from Xamarin to handle the intellisense build process.

    1st solution: (not recommended):
    delete .suo file and reopen the solution

    2nd solution: (recommended):
    right click on xaml files and click on "Run custom tool"

  • Hari-LubovacHari-Lubovac USMember ✭✭
    edited December 2017

    I'm not sure if this relates, but when the InitializeComponent method was being reported as missing for me, the problem related to how originating .xaml files were referenced within .csproj file.

    When I add a content-page via add-new-item VS wizard, related .xaml file gets added as "EmbeddedResource" (within "ItemGroup"). But when I include existing (valid) .xaml and .xaml.cs files via solution explorer (show all files > right-click > include in project), then the .xaml file gets addes as "Page" (within "ItemGroup"). So, then I concluded that I should probably prefer to use the VS-wizard to add/include these "page" files, then copy-paste content (if any) - or deal with fixing this manually again.

    Aside from EmbeddedResource vs Page, the value of "Generator" sub-element was different (I think it was "MSBuild:Compile", but I can't remember), so I changed it back to "MSBuild:UpdateDesignTimeXaml" (like I had in one working example) - but I'm not sure if this would matter (I didn't dare/care to experiment).

    Since then, "InitializeComponent" was back :)

  • AlanStrattonAlanStratton USMember ✭✭
    edited January 2018

    I ran into this issue and found it was my fault. I was using different namespaces in my MainPage. I am using MVVM with Model, View, and ViewModel folders. The fix was ensuring the namespace matched in the .xaml and .xaml.cs files:
    Notice the namespace: SHS.Xam.PCL.View.MainPage below:

    ---- .XAML file --------------
    ContentPage x:Class="SHS.Xam.PCL.View.MainPage"

    --- .XAML.CS file ----------------
    using Xamarin.Forms;
    using SHS.Xam.PCL.ViewModel;

    namespace SHS.Xam.PCL.View
    {
    public partial class MainPage : ContentPage
    {

  • PranatiPranati USMember

    I also had this issue, but correcting the namespace in the XAML and .cs file solved this problem.

  • DirkWeltzDirkWeltz DEMember ✭✭✭
    edited April 2018

    So, now I have this problem too. I couldn't compile my project anymore, because InitializeComponent() isn't found anymore.

    What I use:
    VS 2017 15.6.6 and Xamarin 4.9.0.753 (installed a day ago) on Windows 10

    What I have done up to now:

    • Checked the namespace
    • Cleaned solution
    • Restartet VS and PC
    • Uninstalled ReSharper
    • Added a new xaml page
    • Changed "Embedded resource" to something other and compiled
    • Deleted the complete project and cloned it again from GitHub
    • Deleted all Xamarin.Forms under \users\yourname\.nuget\packages
    • Created a new empty Xamarin.Forms project (shared or .Net standard)

    Nothing of this things work. And it is only with Xamarin.Forms projects. All others work without problems.

    One strange thing is, that I asked someone else to clone the repository and try to compile it. There it works without problems. This leads to the assumption, that there is something strange with my PC.

    Any suggestion, what I could delete, that I get up a running system, that could compile Xamarin.Forms projects?

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    So, now I have this problem too. I couldn't compile my project anymore, because InitializeComponent() isn't found anymore.

    What I use:
    VS 2017 15.6.6 and Xamarin 4.9.0.753 (installed a day ago) on Windows 10

    What I have done up to now:

    • Checked the namespace
    • Cleaned solution
    • Restartet VS and PC
    • Uninstalled ReSharper
    • Added a new xaml page
    • Changed "Embedded resource" to something other and compiled
    • Deleted the complete project and cloned it again from GitHub
    • Deleted all Xamarin.Forms under \users\yourname\.nuget\packages
    • Created a new empty Xamarin.Forms project (shared or .Net standard)

    Nothing of this things work. And it is only with Xamarin.Forms projects. All others work without problems.

    One strange thing is, that I asked someone else to clone the repository and try to compile it. There it works without problems. This leads to the assumption, that there is something strange with my PC.

    Any suggestion, what I could delete, that I get up a running system, that could compile Xamarin.Forms projects?

  • alaskanroguealaskanrogue USMember ✭✭✭

    InitializeComponent() takes the XAML page and creates a runtime object that then you can manipulate via code, but will only do so if the XAML page is categorized as being an "Embedded Resource".

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    Yes, Xaml file is categorized as "Embadded Resource". Is done, but still error comes.

  • Just started with Xamarin and I'm already tired of getting constantly this error, have to spend more time fixing these bugs than actually writing code, It's frustrating

  • arame3333arame3333 GBMember ✭✭

    I am getting this as well. It seems like sometimes something randomly will work, and you just have to hope you can find it.

  • HexenmeisterHexenmeister Member

    5 years is over from the beginning of the discussion. I use VS2019, create new uno solution and in the Shared project have the same error:
    Error CS1061 'MainPage' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'MainPage' could be found (are you missing a using directive or an assembly reference?) App3.Droid, App3.iOS, App3.Wasm ...\App3.Shared\MainPage.xaml.cs 27 Active

    How may I live with it? May Xamarin be used for something more complex than Hello World?

Sign In or Register to comment.