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;
Related
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.
I'm using Microsoft Visual Studio Community 2017. I have created a project with multiple classes to be compiled. The primary class I want the application to run first has public static void Main(string[] args) in it already. In the library, I've set properties to the following:
Target Framework: .NET standard 2.0
Output type: Console Application
Startup object: Main.Game
Still, the error persists with all the forums I have visited.
If you have encountered this problem, please guide me through so I can compile my program. Thank you :)
I was facing this issue in my Visual Studio 2017 15.7.2 version. The cause for this issue in my case was, unknowingly I had changed my Asp.Net Core 2.1 Web API project output type to Class Library. Changing it back to Windows Application fixed my issue. Just sharing the same for the users who does silly mistakes like me.
Unfortunately, Microsoft has this issue open (https://github.com/dotnet/sdk/issues/833) for a long time, but has provided no answer.
Try changing from netstandard2.0 to netcoreapp2.0 for Target Framework.
From here
Try adding the following to you <PropertyGroup>:
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RunCommand>$(MSBuildExtensionsPath64)\..\IIS Express\iisexpress</RunCommand>
<RunArguments>/path:"$(MSBuildProjectDirectory)" /port:18082</RunArguments>
It's usual in Visual Studio.
You have to do 3 things to solve this. In some cases one is enough but sometimes three of them is required.
Open proj.csproj file in the root of the project (if you see no files, try to use ctrl+F to search the solution and find it)
Try to add this <Project Sdk="Microsoft.NET.Sdk.web">
Open your project and right-click on the project main root and go properties
then from the right block select application and the from the white box there select output type to class library.
Try to clean and build the entire solution again.
My Solution contain more than one projects :
Client(Angular) project, Server(API) side project and other project.
In solution, "Single startup project", its set to Client(Angular) project, which cause issue.
I have updated and set Server side(API) project as "Single startup project".
Rebuild solution and error "RunCommand" property is not defined"resolved.
Select Solution > Property > this setting screen available.
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
Having just installed VS2015 Update 1, I discovered the C# Interactive window.
According to the second post in that series, you should be able to import a project from your solution.
When you want to fire up the C# Interactive Window you can just right click your solution and select "Reset Interactive from Project"
However, this option is not available on my project. I'm using a Console Application to test, and have pushed the framework up to 4.6.1 from 4.5. However, this has not worked.
Additionally, I have attempted to manually import the project. Looking at the screenshots on the website, I should be able to do this like this: #r "ConsoleApplication7.exe" but when I do, I get the following exception:
(1,1): error CS0006: Metadata file 'ConsoleApplication7.exe' could not be found
It will pull in via the filepath, e.g:
#r "bin\Debug\ConsoleApplication7.exe"
However, this is a little unwieldly. Especially since whenever you make changes to the classes, it requires a #reset and re-import.
Is there a better way to import Projects into the Immediate instance?
According to the Comment from Jason Malinowski
It doesn't really answer your question, but unfortunately we had to cut the "Reset from Project" command in Visual Studio 2015 Update 1 just because we were crunched getting everything else done. We don't like that it's not there either.
Jason Malinowski
Therefore, at this time (2016-02-04), the "Reset from Project" option is not available.
Projects can be imported manually, by using the following command:
#r "bin\Debug\ConsoleApplication7.exe"
This should work when you are running the REPL with the solution open in the same instance, and when you have only one project.
At other times, you will need to use the full file path
#r "C:\MySolution\ConsoleApplication7\bin\Debug\ConsoleApplication7.exe"
Several years before I started working at this job another developer who is no longer here wrote an application in classic ASP using HTML, vbscript and javascript. This is fine but the problem is that 2 pages were written in C# with an HTML file and a code behind file. There was no solution files for these two pages. They may have been originally created in Visual Studio but they don't exist in it now.
That is important because there is a lot of things that Visual Studio just does for you without even thinking.
My problem is that in these two C# pages I need to get them to reference a DLL. This is a simple task when using Visual Studio. You just add a reference to the project and life is good. But outside of VS nothing seems to work.
I tried putting the dll in the same folder as the pages and then I tried the following:
Using myDLL;
myDLL dll = new myDLL();
myDLL dll = myDLL();
I found some code online that said to create an internal static class and use [DLLImport()] but that didn't work either. It couldn't find the dll or the Entry Point for the dll. I am currently researching how to create an entry point, just in case this is the method to make everything work.
Outside of having to rewrite these pages in vbscript (which I don't have the time to do) I am at a loss.
Has anyone ran into this problem before? Is there something that I can put in the web.Config? Or is this just impossible and I am hosed.
BTW this is all running under the 2.0 .net framework.
If you drop the DLL you want the code to reference into the bin folder of the website, then open the web.config and locate the following section configuration -> system.web -> compilation -> assemblies.
You need to add the display name of the assembly to that list - so that the compiler will reference that assembly during it's late-bound build process.
Now you should be able to use the stuff that's in it on those pages.
If you don't the know the display name of the assembly (typically yourassembly, version=*.*.*.*, Culture=neutral, PublicKeyToken=null for culture-invariant, non-strong-named assemblies) you can open it in a tool like ILSpy (there are others, it's just become my favourite) and it tells you when you select it in it's UI:
sorry for the poor highlighting - jerky hand following far too much coffee
If all the code in that assembly is in a single namespace, also, you can also add a default using to all the .cs or .aspx code in the project by adding that namespace to configuration -> system.web -> pages -> namespaces - making it simpler to use that code in the pages.
I created a VS Solution/Project for my app. I compiled and published it to the web server. When I published it I had it copy all project files.
I ran it and it crashed because it could not find my dll.
I tried adding the lines that Andras mentioned above and it seemed like it was getting me closer but it only changed the errors I was getting.
Then I went into IIS on the web server. I expanded the folder listing under Web Site. I right clicked on the folder that contained my app and made that folder into an application folder.
After I did that everything just worked. So then I thought I would see what happened if I backed out all of the additional code I added to my C# app and the Web.Config file. It still worked. All I needed to do was to make the folder an application folder in IIS and put a Using statement in my C# app and life is wonderful again.
Thanks for all the comments and suggestion. Andras thanks for the link to ILSpy. That is a cool little tool.
Take care,
Robert
I agree with Jon, it sounds like you should try creating a new project for these files. It's always better to leave code better off than you found it. If a new project is not an option for some reason, you should indicate this in your question.