Did not find new element in the hierarchy for item - c#

I am trying to create a simple page for a Xamarin app but am completely unable to proceed with the most basic of steps. I check out the branch from the project repo, and attempt to add a new file. When I do so (Right clicking on folder, Add-> New Item->Content Page) I get this error:
It does actually create the .xaml file but not the .xaml.cs file to go with it. I first tried to manually create the cs file and associate it but ran into increasingly mysterious errors. Today I created them outside of VS before booting it up and both files are now present but with the dotted icon instead of a regular one and the cs file is not nested beneath the xaml file.
If I try to open my projitems file inside VS to make the association I am given the error "Specified method is not supported". If I choose to 'Open With', no screen ever pops up allowing me to choose. After this I closed down VS and edited the projitems file in notepad again and linked the xaml and cs file. This looked as though it worked but when I add it to the main TabbedPage with a simple Children.Add(new MyReviews()); it is not recognized -> The type or namespace name 'MyReviews' could not be found.
These error happen if I make my own branch based on the master or try to add a new file to the master directly. No one else in the project is having these errors.
The only thing I really did differently from the rest is try to get the emulator working for android which apparently has a lot of compatibility issues and requires older versions of the xamarin plugins. I was not able to do this and ended up uninstalling and reinstalling everything twice since I didn't touch the installer software the first time and everything stuck.
Is anyone able to help me debug these issues or know why I am encountering so many at every turn?

I've been in the exact same situation. As it turned out, the rest of my team had added Universal Windows Platform (UWP) support to their VS2017 install, and I hadn't. Running the Visual Studio Installer and adding UWP fixed this issue completely.
Of course, you might not need or want to include UWP support in any of your Xamarin apps (I didn't). It seems most likely that it's just one or two support assemblies that are mssing or wrong without the UWP support, but I haven't found the time or energy to figure out any more details.

Related

C# & VSCode - OmniSharp not working for multi project workspace

VSC is acting a bit weird and I can't figure out how to fix it.
I am doing a tutorial and currently, I have multiple files with the same code. What I can't understand is why one of the files is showing "Problemns" and is highlithing them in the code and the other one doesn't.
Also in the 2nd file, even the breadcrumbs are missing.
1st file
2nd file
OK, so it seems that this is due to the fact that at this moment OmniSharp does not Multi Project support. Each time you want autocomplete and error reporting in a folder from your workspace you need to manually change your OmniSharp folder from here:

Visual Studio 2015 - Xamarin - Android - Getting "resource.id does not contain a definition for xxx" when I try to do anything in the .cs file

Adding Additional Activity .cs and Layout axml Using Visual Studio 2015.
I'm very new to Xamarin and Android development, but have been a developer for a few years using VB and now C#. I have a simple app on Android 4.2 that is getting more complicated as I go along. The simple matter us that I want to add an additional GpsAction.cs and corresponding Gps.axml layout to the project. It seems impossible to find the right combination syntax to achive this. I have a mainActivity with main.axml. In VS 2015 it's very simple to add new but I keep getting "resource.id does not contain a definition for" I would really appreciate your help with this
namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GpsLayout);
string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
// Create your application here
}
}
For people who are still facing this issue, the default Build Action of the layout file would be set to TransformFile. Select the layout, go to the Layout Properties, and in the properties pane, Select AndroidResource as your Build Action. Clean build your project and it should work.
I changed the text field "id" from "#+id/imageView1" to "1", saved, rebuilt and changed it back to "#+id/imageView1", it fixed it. I would like to add, this whole problem came from
Adding a new activity and layout.
Using preexisting code from another app that I had.
Copying and pasting code from the original app to the new Activity
and Layout.
All fairly common stuff, the real problem seemed always to be adding any new Activities and Layouts to a main Activity. It can get very convoluted and with no (known to me) logical way to run down a problem with Xamarin. Don't get me wrong compared to 10 years ago (the last mobile app I tried to write) Xamarin is heaven. Good coding folks, now if I can only figure out why Keyword "this" is error-ring on the added Activity.cs
Just add namespace like that Android.Resource.Id - it's resolve for me
What did work for me (Visual Studio 2017, opening an old Xamarin project):
Delete obj and bin folders, build.
If errors, restart Visual Studio (I know the pain).
Build again
Now the Resource will be visible (of course, if you defined it correctly).
The best solution I have found is to build solution.
Choose Build solution from Build menu (or Ctrl+Shift+B).
This action will resolve the issue.
You Should add set value forandroid:id="#+id/button1" in axml of app, then rebuild the project and try again.
like thisButton button = (Button)FindViewById(Resource.Id.button1); .
Check if you are missing these namespaces in your layout file -
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
(VS 2019) I did the previous solutions and nothing, I had the same problem and the solution for me was to remove '&' from the text of TextView, I was trying to Set the text to "text&text" even &&(I though it was like mnemonics as in WindowsForms) didn't work so I had to remove it and it fixed.
Cleared Main.axml page and Reset and it is working.
My problem was I was trying to debug Xamarin Android project (native) using Xamarin Live Player, connecting using USB cable and selecting my device for debugging solved the problem
Make sure your axml is well formed and rebuild the solution it should work, if you continue facing the same issue then remove axml and add it again then build the solution.
In Visual Studio 2019 when you add a new Android Layout to the Project it is added as .xml file. I already had some created earlier layouts in Resources/layout folder with extension .axml (not .xml) and for me changing the extension .xml -> .axml worked.
I understand that this issue is very old, but I've run into it as well in Visual Studio 2019, and have found a solution.
The issue occurs, for me, when adding an element to the layout and then attempting to add code. The issue appears to be related to the way the project is built.
Add the element to your layout, then build your project before adding any additional code. Apparently Resource.Id does not update with additional members until it's built, and attempting to refer to the new member in the code before Resource.Id recognizes it prevents the project from being built.
Like Maniacz said, in VS 2019 I just had to change the XML to axml extensión to the layout in layout folder under resources
For anyone else looking for an answer despite running clean/build/rebuild which didn't work for me:
I had freshly installed a number of tools for xamarin development in VS. Though a build/rebuild may have actually worked, in my case I believe what also fixed it was closing and re-opening VS. I'm pretty sure I had a few issues, primarily stemming from newly installed tools (android SDKs in my case) requiring VS to be restarted. If you're working on a project already having installed the tools you need, try as others have said - build/rebuild.
I had to modify Build Action for my layout file and re set the original Build Action as it was previously set. This made my visual studio to regenerate the resource ids in Resource.designer.cs file.
Step #1:
Go to properties of the layout file that is missing its ids and click the Build Action DropDown.
Step #2:
Select something from the dropdown other than AndroidResource.
Step #3:
Reselect AndroidResource from that Build Action.
Now, you will have your Resource.designer.cs file regenerated and it will have the reference ids to your controls in the layout file.
Check the Resource.Designer class file. There will be a class like public partial class Id. There the integer IDs of the controls are written. Use them instead of Resource.Id

Unable to Implement CalendarContract w/ Xamarin.Android

I have been wrestling with the Android Calendar for a couple of days now and I'm at my wit's end.
Following the instructions found here:
http://docs.xamarin.com/guides/android/user_interface/calendar/
I have begun a new ICS project and added permissions to read and write to the calendar. According to the instructions linked above I should now be able to "interact with calendar data by using the CalendarContract class." However, when I input the first line of example code:
var calendarsUri =CalendarContract.Calendars.ContentUri;
I get an error saying that "The name 'CalendarContract' does not exist in the current context."
I have download sample code for the CalendarDemo located here:
http://docs.xamarin.com/samples/CalendarDemo/
I can open the project, manipulate the code, deploy it to my test device with the modifications that I have made and it works perfectly. The problem is that I cannot seem to get CalendarContract to "exist in my context" if I create a project from scratch. Even adding in the CalendarListActivity.cs into a new project won't work. This leads me to believe that there is something I have to set in Xamarin Studio, not via code and not indicated in their tutorial, that I have yet to find.
What setting or reference do I need to add into a new or existing project in order to use this feature? I've looked everywhere I can think of and cannot find the elusive switch, checkbox, reference or whatever is required. I've burned three days trying to figure this out and I have lost my patience.
I was able to reproduce the error you're having. I created an ICS project in Xamarin Studio and got the same message. I then loaded the solution in Visual Studio and noticed that the CalendarDemo project has a reference to Mono.Android v4.0, but the one created in Xamarin Studio only referenced Mono.Android v2.2 even though I specified Ice Cream Sandwich. That is why you're not able to build.
Changing the Target version in Project Options didn't seem to do anything. A workaround is to add
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
to the .csproj file. See the CalendarDemo project as an example.
BTW: This is on Xamarin Studio v4.2.2 (build 2). I don't normally use Xamarin Studio, so I have never had to deal with this. I'm not sure if it's a bug in XS, but it certainly isn't expected behavior.
Just as a test, I created another project in Xamarin Studio, but this time I just selected the standard Android Application project. Surprisingly, it referenced Mono.Android 4.3.0. So apparently there's a bug in the Android Ice Cream Sandwich project template.
I recommend using the standard Android Application project going forward.
If you are using Xamarin Studio, right-click on CalendarContact and select Resolve. It should give you two options, first will add "using Android.Provider;" to your using statements and the second will append the code to "Android.Provider.CalendarContract.Calendars.ContentUri"
...or just add manually the using statement. :)
You should import this library
> using Android.Provider;
> using Java.Util;

TFS on VS2010, merging code issues

Recently we have been having problems with TFS and our code base. We have a section of tests that use Webdriver, and a section that use Coded UI. Lately, we've been having problems merging our code after a new build has been pushed out. Some folders show up as a white outline of a folder, which we can right click and select "include in project". We also notice some files missing, and we can't "get latest" to grab them. We have to go some round about way to do it (shelve code, delete local files, get latest, merge code). Even when we do that we still have some issues.
But the main issue we are having is that our Coded UI maps are breaking. Instead of being the normal structure such as:
.uitest
----.cs
----.designer.cs
When we merge in the new code, the UI maps break out like:
.cs
----.designer.cs
.uitest
I opened the .csproj in notepad++ and noticed that both the .cs and .designer.cs files no longer have a dependancy of the .uitest file. Now the .cs file has no dependancy, and the .designer is dependant on the .cs file. We can fix it with relative ease, but it keeps breaking in every build and we have several maps we need to fix. What exactly could the problem be here? Also, referring to my frist problems of files not being included in the project, what could the issue be there?
I asked the same question on the MSDN forums, but the suggestions I have received I have already tried, like creating a new workspace since the other might be corrupt. Still didn't work.
Thanks in advance
Edit: Had a suggestion on the MSDN forums to run VS as administrator. That didn't work either. Not really sure what could be causing this issue. It doesn't seem to be causing problems for everybody because some new builds cause issues for some people but not others. Some more info would be I run on Windows 7 64bit and Visual Studio Ultimate 2010.
In the past I've had issues with TFS that sound similar, 2 of our developers seemed to periodically create problems when merging files into the data store, folders and files would show as not included while the project file would make it in (breaking everything after get latest). Eventually the problem went away but we never truly found the source. I believe it had something to do with our network - maybe a switch issue in combo with the way we mapped working folders to network drives pointing to a shared dev server. Also one of the workstations seemed to have a problem with windows explorer not seeing file updates on the dev server share... developer would have to hit \servername\C$\sharefolder then hit his mapped network drive again before updates would refresh. (And his check in's created the most problems) ... we ran VS2008, TFS2010
Just some ideas...

How to create an Outlet with MonoTouch + Xcode 4 == No Assistant Rules

I'm trying to create my first outlet with MonoTouch and Xcode 4.
When I click on the Assistant Editor it displays No Assistant Rules. It should be showing the .h file code.
What I did was create a new IPad Tabbed Application, and then renamed FirstViewController.cs to SettingsController.cs, and the .designer.cs file didn't get renamed. So I tried closing down MonoTouch and Xcode 4 then manually renaming the file in Finder, then opening up the .proj file in some TextEdit, replacing all instances of FirstViewConoller with SettingsController, reopening up the solution etc, and then seeing if Xcode 4 now knows about the .h file.
For what it's worth, when I click on the Assistant Editor for the SecondViewController, I do get some .h file code displayed in there, and I can drag-drop an outlet onto that.
If you rename the class instead of renaming the file, then both the source file and the designer file will be renamed to be patterned on the new name of the class.
That said, the reason you probably aren't getting header files for your SettingsController class is because of a race condition in MonoDevelop (fixed in the upcoming 2.8.8.2). What is happening is that MonoDevelop is still indexing (or hasn't started) your project, getting a list of known classes and their properties/methods/etc. Since that information is incomplete when you double-click a .xib to launch Xcode, the xcode-sync logic doesn't know about those classes and so doesn't sync out any mirrored ObjC classes for them.
There is a similar question here Renaming Controller classes in MonoTouch MonoDevelop with a similar issue about renaming ViewController files. Unfortunately this question doesn't have an accepted answer.
There doesn't seem to be any workaround for renaming. It may have to do with how MonoTouch interacts with the Obj-C behinds the scenes. I know it's not the best approach, but what about starting a new project, creating a new UIViewController named SettingsController (instead of renaming) and just replacing where it calls/navigates to FirstViewController with SettingsController?

Categories

Resources