InitializeComponent Does not Exist in the current contenxt

PaaKofiPaaKofi USMember ✭✭

I have suffered the indignity of this bug in VS2017, i have read and applied all the suggestions i found but still not working for me. i have even cleaned my PC and reinstalled VS.
what i see is that *.g.c files not being created

I need help!

Best Answer

  • PaaKofiPaaKofi US ✭✭
    Accepted Answer
    > @JGoldberger said:
    > @PaaKofi
    >
    > There is an open issue on the Xam.Forms github repository about problems building when getting that error about the InitializeComponent method: https://github.com/xamarin/Xamarin.Forms/issues/2863
    >
    > Perhaps comment on that issue so it can be determined if you are hitting the same issue.

    Ok thanks. I had a look at that.

    I figured out that the issue was with xamarin target files.

    I reinstalled VS17 but the problem still persist until I deleted all the left overs from VS installations and cleared all sdks. Reinstalled VS and all is working fine now.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Its a false positive. Just clean and rebuild and you should be fine.

  • PaaKofiPaaKofi USMember ✭✭

    i have done more than 1 milion. same result. i have unloaded the Android proj. the PCL will not compile

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    If it won't compile its not for that InitializeComponent error. We all see that. Happens to everyone. Its a false flag.
    There is something else going wrong. What other errors are you getting?

    Have you tried closing and rebooting then reopening the solution? The Loading... process does some sort of clean up magic many times.

  • PaaKofiPaaKofi USMember ✭✭

    InitializeComponent Does not Exist in the current contenxt, thats the only error. it never goes away

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    If you do a completely new solution. No changes. Just the generic "Welcome to Xamarin" project.
    Clean it.
    Close it.
    Open it.
    Run it.
    what happens?

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:
    If you do a completely new solution. No changes. Just the generic "Welcome to Xamarin" project.
    Clean it.
    Close it.
    Open it.
    Run it.
    what happens?

    do i change anything at all, like update Nuget etc?
    i do that, going to a meeting

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @PaaKofi said:

    @ClintStLaurent said:
    If you do a completely new solution. No changes. Just the generic "Welcome to Xamarin" project.

    do i change anything at all, like update Nuget etc?

    No. Change nothing. Let it work off whatever version is specified in the Visual Studio templates.
    Does it work out-of-the-box?

  • PaaKofiPaaKofi USMember ✭✭

    @PaaKofi said:

    @ClintStLaurent said:
    If you do a completely new solution. No changes. Just the generic "Welcome to Xamarin" project.
    Clean it.
    Close it.
    Open it.
    Run it.
    what happens?

    do i change anything at all, like update Nuget etc?
    i do that, going to a meeting

    in a meeting now, i will finish about 1 hour, i dying to get out and do it your way! i will let you know soon as i finish

  • PaaKofiPaaKofi USMember ✭✭

    S> @PaaKofi said:

    @PaaKofi said:

    @ClintStLaurent said:
    If you do a completely new solution. No changes. Just the generic "Welcome to Xamarin" project.
    Clean it.
    Close it.
    Open it.
    Run it.
    what happens?

    do i change anything at all, like update Nuget etc?
    i do that, going to a meeting

    in a meeting now, i will finish about 1 hour, i dying to get out and do it your way! i will let you know soon as i finish

    Error MSB4062 The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\Jason.nuget\packages\xamarin.forms\3.0.0.561731\build\netstandard2.0\Xamarin.Forms.Build.Tasks.dll. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. FarmDirect C:\Users\Jason.nuget\packages\xamarin.forms\3.0.0.561731\build\netstandard2.0\Xamarin.Forms.targets 51

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    If you can't run an out-of-the-box, generic, vanilla "Welcome to Xamarin" solution...
    Honestly sounds environmental. Visual Studio isn't right... Or you don't have the Java SDK's right... Or something to that effect.
    You can try.
    Clean it
    Close it
    Delete all the bin and obj directories
    Build each project, ONE AT A TIME
    Then Rebuild Solution

    If that doesn't get it, Re-install Visual Studio - WITH EVERY WORKLOAD, OPTION, EXTRA, PACKAGE - leave nothing unchecked for anything whether you think it is related or not!

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:
    If you can't run an out-of-the-box, generic, vanilla "Welcome to Xamarin" solution...
    Honestly sounds environmental. Visual Studio isn't right... Or you don't have the Java SDK's right... Or something to that effect.
    You can try.
    Clean it
    Close it
    Delete all the bin and obj directories
    Build each project, ONE AT A TIME
    Then Rebuild Solution

    If that doesn't get it, Re-install Visual Studio - WITH EVERY WORKLOAD, OPTION, EXTRA, PACKAGE - leave nothing unchecked for anything whether you think it is related or not!

    I've done all that! trust me

  • PaaKofiPaaKofi USMember ✭✭

    with Prism I get this
    Severity Code Description Project File Line Suppression State
    Error CS0103 The name 'InitializeComponent' does not exist in the current context FD C:\Development\FD\FD\FD\App.xaml.cs 25 Active

    Severity Code Description Project File Line Suppression State
    Error The "ResolveLibraryProjectImports" task failed unexpectedly.
    System.IO.FileNotFoundException: Could not load assembly 'FD, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
    File name: 'FD.dll'
    at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
    at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
    at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection1 jars, ICollection1 resolvedResourceDirectories, ICollection1 resolvedAssetDirectories, ICollection1 resolvedEnvironments)
    at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
    at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() FD.Android

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @PaaKofi said:
    I've done all that! trust me

    Not sure what to tell ya. If the vanilla "Welcome to Xamarin" don't work you've got some sort of PC/installation/framework/IDE problem.

    Until you can make "Welcome to Xamarin" work - its pointless to try anything else such as Prism etc. Its like saying "I can't get the car engine to run - I've checked the transmission fluid and all the air in the tires is good but it still won't run. I even changed drivers behind the steering wheel. What could be the reason the car won't start?"

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Just checking... You are using VIsual Studio 2017 build 15.7.4 - Right? The latest version of Visual Studio as of July 2018.

  • PaaKofiPaaKofi USMember ✭✭

    @PaaKofi said:

    @ClintStLaurent said:
    If you can't run an out-of-the-box, generic, vanilla "Welcome to Xamarin" solution...
    Honestly sounds environmental. Visual Studio isn't right... Or you don't have the Java SDK's right... Or something to that effect.
    You can try.
    Clean it
    Close it
    Delete all the bin and obj directories
    Build each project, ONE AT A TIME
    Then Rebuild Solution

    If that doesn't get it, Re-install Visual Studio - WITH EVERY WORKLOAD, OPTION, EXTRA, PACKAGE - leave nothing unchecked for anything whether you think it is related or not!

    I've done all that! trust me

    I this this is the issue
    C:\Users\Jason.nuget\packages\xamarin.forms\3.0.0.561731\build\netstandard2.0\Xamarin.Forms.targets(51,5): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited July 2018

    FYI:
    Just just took VS2015 and built an out-of-the-box Solution. I needed to know for my own clarity that something wasn't broken and the last round of updates, before I continued to spout off. It worked fine.
    Then I did the same for VS2017 - That worked fine.
    Then I rolled the VS2015 test back to XamForms 2.5.x - That worked.
    Now I'm using that new VS2015 solution to do some testing for a vendor's API. I'm actually doing my best to break their API, or find a magic combination that will cause it to seize up. So far no good: I can't find what is breaking the API.
    But I can't seem to break the out-of-the-box solution either.

    So if you think there is an issue with the Xamarin.Forms3 nuget - roll it back to the latest 2.5.x version. I know it runs as I just did it.

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:
    FYI:
    Just just took VS2015 and built an out-of-the-box Solution. I needed to know for my own clarity that something wasn't broken and the last round of updates, before I continued to spout off. It worked fine.
    Then I did the same for VS2017 - That worked fine.
    Then I rolled the VS2015 test back to XamForms 2.5.x - That worked.
    Now I'm using that new VS2015 solution to do some testing for a vendor's API. I'm actually doing my best to break their API, or find a magic combination that will cause it to seize up. So far no good: I can't find what is breaking the API.
    But I can't seem to break the out-of-the-box solution either.

    So if you think there is an issue with the Xamarin.Forms3 nuget - roll it back to the latest 2.5.x version. I know it runs as I just did it.

    thanks for all that. I have tried that. when I comment out the InitialComponent method, the app atcally runs. and I get the the welcome message displayed.

    something is happening. I uninstall VS17 and try agin.

  • PaaKofiPaaKofi USMember ✭✭

    I did clean up and stayed all night long still same issue. the autogenerated file not generating the *.g.c files that I think is the issue. if I create the method it works and runs fine, but that's not the way!

  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    @PaaKofi said:
    InitializeComponent Does not Exist in the current contenxt, thats the only error. it never goes away

    Hi @PaaKofi,

    Please check your files BuildActions.
    Your XAML file build action should be EmbeddedResource and c# file build action should be compile.
    Right click on files then properties and then check the build action for both files.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    the autogenerated file not generating the *.g.c files that I think is the issue.

    You're just not going to accept that you're installation is f'd up, are you?

    Its not the autogenerated file that is a problem. Its your installation - which may or may not be manifesting itself in all sorts of weird way - maybe in generated files, maybe not. The generated file is a SYMPTOM, not the CAUSE.

  • PaaKofiPaaKofi USMember ✭✭

    @ManojkumarMali said:

    @PaaKofi said:
    InitializeComponent Does not Exist in the current contenxt, thats the only error. it never goes away

    Hi @PaaKofi,

    Please check your files BuildActions.
    Your XAML file build action should be EmbeddedResource and c# file build action should be compile.
    Right click on files then properties and then check the build action for both files.

    all build action are all correct! thanks, i will continue to dig and share my experience!

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:

    the autogenerated file not generating the *.g.c files that I think is the issue.

    You're just not going to accept that you're installation is f'd up, are you?

    Its not the autogenerated file that is a problem. Its your installation - which may or may not be manifesting itself in all sorts of weird way - maybe in generated files, maybe not. The generated file is a SYMPTOM, not the CAUSE.

    my project was all working good before until i installed xamarin update to the latested version.
    could be the there is a corruption somewhere, all my WPF applications are working good, my MVC applications all are working.

    i will continue to find that help. i am insalling also on a new laptop !

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:
    FYI:
    Just just took VS2015 and built an out-of-the-box Solution. I needed to know for my own clarity that something wasn't broken and the last round of updates, before I continued to spout off. It worked fine.
    Then I did the same for VS2017 - That worked fine.
    Then I rolled the VS2015 test back to XamForms 2.5.x - That worked.
    Now I'm using that new VS2015 solution to do some testing for a vendor's API. I'm actually doing my best to break their API, or find a magic combination that will cause it to seize up. So far no good: I can't find what is breaking the API.
    But I can't seem to break the out-of-the-box solution either.

    So if you think there is an issue with the Xamarin.Forms3 nuget - roll it back to the latest 2.5.x version. I know it runs as I just did it.

    PS, i get better result using the Prism Template than Cross-Platform template!

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    i am insalling also on a new laptop !

    That should be a real test. Full VS2017 installation (everything). And it should run great.

    I admit that sometimes upgrading can cause issues. It used to be far worse than recently. I've been updating regularly on my VS2015 and VS2017 installations and (fingers crossed) so far no problems. FYI: I even have VS2015 an VS2017 running side-by-side on the same laptop. I use them simultaneously even.

  • PaaKofiPaaKofi USMember ✭✭

    @ManojkumarMali said:

    @PaaKofi said:
    InitializeComponent Does not Exist in the current contenxt, thats the only error. it never goes away

    Hi @PaaKofi,

    Please check your files BuildActions.
    Your XAML file build action should be EmbeddedResource and c# file build action should be compile.
    Right click on files then properties and then check the build action for both files.

    all build action are all correct! thanks, i will continue to dig and share my experience!

  • AmitManchandaAmitManchanda USMember ✭✭
    edited July 2018

    @PaaKofi This error also comes when the class name is mismatched between xaml and xaml.cs files as it does not match with the global application file.

    So go to App.xaml and see class Id, It should match the App.xaml.cs class name and also of type with the inherited class, e.g. App.xaml.cs inherited Application class so the App.xaml should be using this Application as xaml tags

    As if you tried all the clean and rebuild solution

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    That shouldn't be the case if he followed instructions with a brand new "Welcome to Xamarin" and changed NOTHING.
    That's always the first test - if that won't run, its your installation/environment and not anything in the solution itself.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Of course there are several other threads for the same thing if the open would just do a search of the site.
    https://forums.xamarin.com/discussion/comment/338289#Comment_338289

  • PaaKofiPaaKofi USMember ✭✭

    @ClintStLaurent said:
    That shouldn't be the case if he followed instructions with a brand new "Welcome to Xamarin" and changed NOTHING.
    That's always the first test - if that won't run, its your installation/environment and not anything in the solution itself.

    i agree with you clint, when clean and reinstalled i had different errors coming up, like sysmtem.io, i have this time clean all and clean Android SDK.

    lets see this time

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @PaaKofi

    There is an open issue on the Xam.Forms github repository about problems building when getting that error about the InitializeComponent method: https://github.com/xamarin/Xamarin.Forms/issues/2863

    Perhaps comment on that issue so it can be determined if you are hitting the same issue.

  • PaaKofiPaaKofi USMember ✭✭
    Accepted Answer
    > @JGoldberger said:
    > @PaaKofi
    >
    > There is an open issue on the Xam.Forms github repository about problems building when getting that error about the InitializeComponent method: https://github.com/xamarin/Xamarin.Forms/issues/2863
    >
    > Perhaps comment on that issue so it can be determined if you are hitting the same issue.

    Ok thanks. I had a look at that.

    I figured out that the issue was with xamarin target files.

    I reinstalled VS17 but the problem still persist until I deleted all the left overs from VS installations and cleared all sdks. Reinstalled VS and all is working fine now.
  • nick5454nick5454 USUniversity ✭✭✭

    So I fixed mine, by pasting into notepad. Undo on the file with Source control. Paste each change 1 by 1 and it's fixed. I think there is some kind of line ending that is confusing the compiler

  • HermannRoschHermannRosch USMember ✭✭

    I had a similar problem, but it was because my CreateItem.xaml file had

    x:Class="MyNamedApp.Views.CreateItem"
    

    But my CreateItem.xaml.cs code-behind file had a different namespace

    namespace MyNamed.Views
    {
    ...
    }
    

    So I just corrected the CreateItem.xaml file to match the namespace as

    x:Class="MyNamed.Views.CreateItem"
    

    Getting rid of the extra App in the x:Class and the problem was solved.

    Names must match.

Sign In or Register to comment.