Xamarin Forms InitializeComponent does not exist - xaml

I am learning Xamarin Forms for Visual Studio 2015 and trying to create a simple Shared project using Xaml but I keep getting InitializeComponent does not exist (as well as any reference to Xaml controls in cs classes).
It is my understanding that in the latest versions of Xamarin, Xaml works in Shared Xamarin Forms Projects (and not only in PCL projects). I've tried running the latest betas that got released less than a month ago but still no luck.
Any advice is greatly appreciated.

Turns out I had to manually change the properties for all Xaml files like so:
Build Action: Embedded resource
Custom Tool: MSBuild:UpdateDesignTimeXaml
For some reason adding new Xaml forms files doesn't set these by default in VS2015 with latest Xamarin.

I had the same issue. And it turned out to be that fully qualified Class Name (x:Class attribute in the main node) in the XAML file must match exactly the xaml.cs file's name. I corrected the namespace casing and it worked!!

This happens when your XAML markup is invalid. There is a background compilation task that parses the XAML file and generates a code file (this is normally hidden from the developer) which declares those control references. If your XAML is not valid then this task will fail silently, and your first hints are the symptoms you describe.
Comment out the contents of your XAML file using standard XML comment syntax (wrap it with <!-- and -->), then rebuild your project to clear out all of the errors. You may also need to comment out some code in your .cs files temporarily to get it to build. Once you get it building, then you can go back and start uncommenting your XAML until you find the part that was breaking it.

Try it:
Open the Package Manager Console, put the follow line:
update-package -project your_pcl_project_name -reinstall

Related

InitializeComponent does not exist

InitializeComponent();
This code line appeared in all my Xaml pages' constructors in code behind.
It throws the following error:
InitializeComponent does not exist.
Now I cannot debug any page in my project although I have commented out this line.
How can I fix this?
Any help would be greatly appreciated.
Note: I'm using Xamarin Forms Portable project.
Update: When I comment out this line and run the pages, only an empty screen shows up in both IOS and Android although my pages were working correctly without error before.
Update 2: now the InitializeComponent lines are disappeared but the pages that I debug are still totally blank.
I have asked a question about this new problem on here.
I had also the same problem in Xamarin Forms Application.I fixed it by changing the Build Action to:
Embedded resource
for .xaml and .cs file both using property window.
Hope it may help you.
Change something in the page, then save it. Scarily this resolves the issue sometime.
If that doesn't work.
Update your nugget packages so Xam Forms is the latest.
"Clean" your project
Go to your project dir and delete the bin and obj from your projects via File Explorer.
Rebuild it.
Good luck.
Be sure that your Xaml page has property Custom Tool set to MSBuild:UpdateDesignTimeXaml
'Its not an issue. You can try to build your solution. Hopefully it will bulid perfectly. Most of the time I also get red under line on InitializeComponent(); like you same. Its a problem of Xamarin studio and Visual studio'
Is it the first XAML page you create in the project? or you created other pages and they don't contain this problem?
you can Check the comments here: http://forums.xamarin.com/discussion/17638/initializecomponent-does-not-exist/p4
Have you renamed your page? All XAML pages have a viewable partial class (the one you enter your logic code in to) and a hidden, system generated partial class.
If you renamed the class but did not use the VS rename macro, your system generated partial class no longer matches your editable partial class.
Try running 'Clean Solution' and 'Rebuild Solution' (both in the 'Build' menu) to see if VS can automatically detect and fix this for you.
If that doesn't work, make sure your pages are set as partial classes e.g. public partial class MyPage : Page
If you still have no luck, manually delete the 'obj' folder in your project's root folder, then rebuild again.
Simple trick:
Just edit your Xaml code..(Put space also enough..But need editing)
After edit the xaml page save project..
Now check error disappears..
In my case this was a result of intermediate build paths being too long for Windows. Moving my solution to just off the drive root C:\dev{solution} in my case solved the problem.
I had this problem because the namespace of my .xaml file did not match the namespace of the .xaml.cs file. Fixing the namespaces so they matched corrected the problem.

Cannot get Xamarin Xaml Intellisense working in VS 2015

I've been trying to get intellisense working for quite some time now, and am unable to see anything outside of
!
![CDATA[
?
Visual Studio 2015 Update 2
Resharper is installed but disabled
Referencing the latest pre-releases of Xamarin Forms (2.3.0.38-pre2)
Xamarin for Visual Studio (4.2.21)
Portable project referencing the proper 2.3.0.38-pre2 targets file from NuGet
Enable XAML Language for Xamarin.Forms
What else am I missing? I feel like it shouldn't be this difficult.
I resolved this issue by doing a simple workaround and here is the solution.
Right-click the XAML file in the Solution Explorer and select
Solution 1: "Open With... > Source Code (Text) Editor".
and in another time this also worked for me:
Solution 2: "Open With... > Source Code (Text) Editor with Encoding"
This workaround gave me the desired XAML IntelliSense even without installing the extra "Enable XAML Language for Xamarin.Forms" extension and even with ReSharper installed but suspended.
Extensions > Tools > Enable XAML Language for Xamarin.Forms
Enable XAML Language for Xamarin.Forms
Enables the VS built-in XAML language service to provide editing and intellisense for Xamarin.Forms XAML files.
https://visualstudiogallery.msdn.microsoft.com/8195a8e2-a842-4389-a8cb-34e4672e2e13
Update:
From #Jeff:
Seems I had to completely uninstall Resharper, not just disable it. Then reinstall the "Enable XAML Language for Xamarin Forms extension".
Additional info:
http://www.cazzulino.com/enable-xaml-forms-intellisense.html
Xamarin XAML Enabled:
XML Enabled and thus no Xamarin XAML Intellisense:
The reason why Intellisense is not appear in editor is that Xamarin XAML is not opened as file with content type xaml but file with content type xml.
To open xamarin XAML file as file with content type xaml simply in solution explorer right click the xaml file and select Open With... In popup select "XAML Designer with Encoding" and click OK.
Solution below is if you edit Xamarin xaml as file with content type xml. But this solution is not correct, IntelliSense then not always correctly suggests.
To take advantage of Intellisense the Visual Studio must get appropriate definition of xml namespace for Xamarin.Forms. For the Xamarin.Forms Visual Studio needs xml definition for namespace http://xamarin.com/schemas/2014/forms.
This definition can be provided to Visual Studio by two ways:
You can use xsd file and this file then register to xml schemas - after you open xaml file, the menu Xml/Schemas appear.
You can this definition create by assembly attribute XmlnsDefinitionAttribute. This attribute you can found in Portable.Xaml nuget package.
Suitable for Xamarin.Forms is the second way(using attribute).
If you use Xaml in portable library, restore(download and install) this nuget package to this library.
If you use shared project, then restore this nuget package to all projects referencing this shared project.
Then insert this attribute to appropriate place. I believe that the App.xaml.cs(if you use generated name App) is a good place. The code could look like this:
using Portable.Xaml.Markup;
using Xamarin.Forms;
[assembly: XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms")]
namespace YourAppNamespace
{
public partial class App : Application
{
public App ()
{
this.MainPage = new MainPage();
}
}
}
And the rebuild solution, as I believe, might not be necessary to work Intellisense for Xamarin.Forms.
This worked for me:
right click on .xaml file and then select "Open With.." and select "XAML Designer" and also "Set as Default" then intellisense worked great.
I install the Extension Enable XAML Language for Xamarin.Forms from
Enable XAML Language for Xamarin.Forms
Still the intellisense was not working. I just need to close all tabs and close the visual studio. After re-starting Visual studio I open solution and XAML file. The instellisense is working fine.
worked for me
Right click on Your XAML file and choose Option
Open With=>Source Code(Text) Editor with Encoding=>Set as default=>Apply and choose option Auto....
Seems I had to completely uninstall Resharper, not just disable it. Then reinstall the Enable XAML Language for Xamarin Forms extension.
Jeff's answer almost worked for me, but I had to do one additional step:
Because I had previously uninstalled and reinstalled Xamarin, I had to update from 4.0.1 to the latest stable (4.1.1.3 as of this date). After that Intellisense started working!
I have Resharper installed on VS2015update3, and XAML Designer didn't work for me.
But accidently I found XML (Text) Editor works. That's Resharper that makes effet.
No wave-line beneath the tag
Perfect prompt everywhere: XML Tags, Properties, available Values
Only things: it doesn't color too much, and F7 do not send me to its code-behind.
VoilĂ , hope this could help
I resolved this issue by doing a simple workaround and here is the
solution.
Right-click the XAML file in the Solution Explorer and select
Solution 1: "Open With... > Source Code (Text) Editor".
and in another time this also worked for me:
Solution 2: "Open With... > Source Code (Text) Editor with Encoding"
Actually, I found that for me it even worked by simply choose:
Solution 2: "Open With... > Automatic Editor Selector (XML)" and then reopening VS.
I also found that the problem began after editing .xaml file outside of VS, by right-clicking the file and choose "Edit".

UWP Media Element Custom control giving exception

I am having a very strange situation over here.
I refered to the UWP samples and tried Custom Media transport controls sample. I ran it and it was working just fine, like its supposed to work. But then I tried and made my own project and I copied exactly everything which was in sample project not even name of file or folder was different. And then when I ran that project it gave me debugger unhandled exception and open App.ig.cs some file like this and when i continue it stop debugging. Below is the attached snapshot of that error. Any help is appreciated this is a really strange error for me as it makes no sense at all.
Note: I have tried to run it in both blend and visual studio
I solved it by simply ignoring the style of transport controls provided in the sample, for some reason that style was not able to verify some properties so I deleted that file and made my own style file, I copied the style of default media controls and edited them, it worked for me :)

In a VB project, is it possible to have a resx file with the same name than a form?

Good Morning,
I'm working in a VB project (usually I work mostly on C#) and there is an issue at the compilation that I don't understand:
In my VB project I have a Windows Form (with its own Designer.vb and .resx) and a Resources file (with its Designer.vb), both have the same name, and it seems that it produce the following compilation error:
Error 13 The item "obj\Debug[projectName].[fileName].resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
I can't change the name of one of them as it's an internal design pattern (and it works in C# projects).
Doesn't VB accept such pattern ? If yes, are there any workaround possible ?
Or do I have something wrong in one of my project files ?
Regards
Edit: As my problem may not be very clear, here is the pattern I have to respect in this project :
This doesn't compile. In VB only as I'm using this pattern in C# projects without any issues.
You probably have a duplicated entry inside the form.designer. I ran across this problem once
Goto to your Solution Explorer, Select your project and click on the show all files icon at the top of the Solution Explorer. You should then be able to expand out your form.vb to see all the sub files. Look for a frmMain.Designer.vb and check it for a duplicate resource entry. If that doesn't work try cleaning your Solution
Extracted from here, check the link it may help:
VB.net designer error
Edit: I would delete the form. Save the code behind and create it with another name pasting the code.
Finally I found where the problem was:
It was an issue with namespaces, as VB generated in VisualStudio doesn't provide any namespace by default in WinForms, ones I gave a namespace to the form and the designer of the form, and gave a different namespace to the second resx (via it's properties/Custom Tool Namespace) it compile.

Intellisense not working for XAML in VS2012 and only partially in Blend

I'm trying to get RC of Visual Studio 2012 working for XAML files. I can't seem to get any XAML Intellisense and the option within Tools is greyed out.
I've also tried to run the solution using Blend, however I only get Intellisense for custom controls such as telerik then.
When ever I drag controls onto the design surface I get an "Object reference not set to an instance of an object" exception but the control is still added to the surface.
I've read that this was a bug within VS11 and was fixed with in the Visual Studio 2012 RC.
I've created a new Silverlight Application and the intellisense is working so i'm wondering if its an issue with how my projects are set up.
I have all of my Styles within a separate themes project, which is referenced by other all other projects. Within the designer these references show up as errors but when the application runs they are resolved fine.
Would unresolved resources at design time affect Intellisense?
Click "Build -> Clean Solution", then "Build -> Build Solution". ("Rebuild Solution" alone doesn't work.) [Source]
If you have a reference to any of the expression blend dlls for interactions and you are using silverlight5 you will need to update the following dlls:
Microsoft.Expression.Controls.dll
Microsoft.Expression.Effects.dll
Microsoft.Expression.Interactions.dll
System.Windows.Interactivity.dll
Blend + SketchFlow Preview for Microsoft Visual Studio 2012
http://www.microsoft.com/en-us/download/details.aspx?id=30702
Ref Location:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\Silverlight\v5.0\Libraries
Exact same problem here, using WPF.
In my case, removing:
<Page.Resources>
<vm:AnyViewModel x:Key="anyViewModel" />
</Page.Resources>
Solve my problem...
One known cause of XAML Intellisense failure is if System.Windows.Controls.Toolkit is one of the project references. I've seen where deleting that reference instantly fixes the problem. The problem is described in the comments of this Connect bug for VS2012 Beta, but it applies to the RC with the July update as well.
I've found that some xaml designers for a control have this issue, where other controls are just fine.
The problem (in my case) seems to be if parameters are null or events call uninitialized singletons. Something the designer gives you a stack trace and other timers renders with no problem.
I've found by changing the back-end code for pages that don't have Intelli-sense to include DesignerProperties always fixes the issue (in my cases).
public Homing()
{
InitializeComponent();
if (DesignerProperties.GetIsInDesignMode(this))
return;
// some other code here that may have uninitialized members
}
t
I'm not sure if I had the same problem, but Intellisense mysteriously stopped working for me within a XAML file. I tried cleaning the build as someone suggested, but that didn't work.
After I restarted Visual Studio 2013, the Intellisense in the XAML page started to work again.