I'm starting to learn Xamarin, and I'm stuck in this problem. There is an exception thrown
Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=Chris...
https://www.removeddit.com/r/greentext/comments/a9rwbb/anon_goes_to_christmas_dinner/eclyp8c
Background: I'm developing a small personal project that opens removeddit in a browser automatically from my phone through reddit.
The issue is it throws the exception when I run the code below. That probably would have been my mistake and I haven't googled enough. But surprisingly when I copy-paste and override the output link with the URI produced by the three lines of code in pre-processing, as observed in the debug line, the browser opens up with the right webpage.
Current Code that doesn't work:
//Let's call it pre-processing
string outputLink = inputLink.Substring(inputLink.LastIndexOf(' '));
outputLink = outputLink.Replace("reddit", "removeddit");
outputLink = outputLink.Trim();
Log.Info("DebugTag", outputLink);
Uri uri = Uri.Parse(outputLink);
var intent = new Intent(Intent.ActionView, uri);
StartActivity(intent);
Replacement code that makes it work in place of pre-processing:
string outputLink = "https://www.removeddit.com/r/greentext/comments/a9rwbb/anon_goes_to_christmas_dinner/eclyp8c"
I absolutely have no idea what the mistake might be and I'm completely baffled.
EDIT: Added exception I'm observing.
So I followed this link http://www.c-sharpcorner.com/UploadFile/b696c4/how-to-upload-and-display-image-in-mvc/ given by #Div and it just gave me errors at ContentRepository service = new ContentRepository();. How am I suppose to replace that with something else that contain UploadImageInDataBase like int i = service.UploadImageInDataBase(file, model); ?
Private readonly DBContext db = new DBContext();
Gives me error "is inaccessible due to its protection level." And it wont be usable since it gives error "Cannot resolve", but I replaced it with private TestEntities db = new TestEntities(); and it works then. Hopefully it will cover everything?
I cant add anything inside var Content = new Content { as I getting "Cant resolve symbol X" inside it.
Then at
List<ImageVm> contentModel = content.Select(item => new ImageVm()) {
I'm getting following error:
Cannot implicitly convert type 'System.Linq.IQueryable'
to 'System.Collections.Generic.List'. An explicit
conversion exists (are you missing a cast?)
I followed every step carefully and I can't get any further.
The author basically just said "add this code" without explanation and I've no idea how to solve it.
Any idea how to solve it or have any better guides?
Today I updated to Xamarin.iOS 8.6.0.51 and switched to the new Unified API.
Now I want to get the keyboard size (this code worked before):
var val = new NSValue (notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey).Handle);
RectangleF keyboardSize = val.RectangleFValue;
With the help of the migration tool the RectangleF is converted to CGRect, but the errors I'm getting here are
Error CS1540: Cannot access protected member
Foundation.NSValue.NSValue(System.IntPtr)' via a qualifier of type
Foundation.NSValue'. The qualifier must be of type
`MyApp.SomeViewController' or derived from it (CS1540)
and
Error CS0122: `Foundation.NSValue.NSValue(System.IntPtr)' is
inaccessible due to its protection level (CS0122)
How can I solve this? I can delete new NSValue(...), but RectangleFValue still doesn't work and I would need a replacement/another way.
Edit:
According to jonathanpeppers I modified my code to:
NSValue keyboardFrameBegin = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
CGRect keyboardSize = keyboardFrameBegin.CGRectValue;
This doesn't throw an error anymore, but I can't test it further because I'm in the process of migrating to the Unified API and there are still some errors to correct.
Can you just use a cast:
var val = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
RectangleF keyboardSize = val.RectangleFValue;
Only rarely should you have to mess with handles in Xamarin.iOS.
To be absolutely sure what to cast to, debug and see what the underlying type is first:
NSObject val = notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
Console.WriteLine("Type: " + val.GetType());
The .ctor(IntPtr) constructors in NSObject could be misused and causes issue later. Also, like #jonathanpeppers mentioned, they were not required for many scenarios (like this one).
Another way to do this (e.g. if you have nothing else but an handle), as documented here, is to use the ObjCRuntime.Runtime.GetNSObject<T> (IntPtr) method. That will ensure the NSObject-subclass is created correctly.
I'm trying to follow the TTNavigatorDemo to implement TTNavigator on a MonoTouch app.
My first question is what do I assign to PersistenceMode (I was expecting an enum but it asks me for an int!):
Navigator = new TTNavigator();
Navigator.Window = window;
Navigator.PersistenceMode = ???;
Second,
I've declared a url map:
Navigator.URLMap.FromToSharedViewController("tt://tabBar", Class.GetHandle(typeof(MainTabBarController)));
But when I try to navigate to it by calling Navigator.OpenURL(#"tt://tabBar", false); I'm getting an error:
-[TTNavigator openURL:animated:]: unrecognized selector sent to instance 0x9c45120
I've also tried to register the mapping with a Selector:
Navigator.URLMap.FromToSharedViewController("tt://tabBar", Class.GetHandle(typeof(MainTabBarController)), new NSObject(Selector.Init));
Any pointers on how to get TTNavigator to work on Monotouch? Or is there a better alternative?
I am into my sixth hour battling with what hopefully should have a simple solution, so I thought I would post here.
I have an feature with a feature receiver whose sole purpose is to activate a deployed list definition feature and then create an instance of that new list definition.
The list definition feature, called "Custom Access List", is scoped at web.
So my feature receiver activates this list definition feature, having GUID "1E503BDA-803B-4a1a-A042-019FA1A70C4C":
...
string featureGuid = "1E503BDA-803B-4a1a-A042-019FA1A70C4C"; // my 'Custom try
{
SPFeatureCollection featureCollection = web.Features;
featureCollection.Add(new Guid(featureGUID), true); // activat the 'Custom Access List' feature
}
catch (Exception e)
{
// log exception
}
This code executes fine, and the list definition feature is activated, and the new list definition appears in the "Create" site menu option in the UI.
However, this is where my issue starts. The next line of my feature receiver code then tries to create an instance of this newly-available list:
SPListTemplate listTemplate = web.ListTemplates["Custom Access List"]; // exception! Value does not fall within the expected range
web.Lists.Add("My new custom access list","", listTemplate);
But the line SPListTemplate listTemplate = web.ListTemplates["Custom Access List"]; throws an exception with "Value does not fall within the expected range." - the list template, despite being deployed, visible and available in the UI under the "Create" site menu action, cannot be found in the receiver code.
Debugging the code confirms that the web.ListTemplates SPListTemplateCollection does not contain a entry for this new "Custom Access List", despite the UI suggesting otherwise.
And here is the weird thing. An exception is thrown, but if I then re-run the code i.e. reactivate the feature in the UI, to re-execute that feature receiver, the list template is then found -
SPListTemplate listTemplate = web.ListTemplates["Custom Access List"]; // found this time. It sees it the second time around
web.Lists.Add("My new custom access list","", listTemplate); // works fine
So, in a nutshell - initially, after activating a feature which, through receiver code, activates a list definition feature, that list definition is not visible until after a "postback" or some form of "SPWeb refresh". Then it is visible.
Am I missing something here? A call of web.Update() here:
try
{
SPFeatureCollection featureCollection = web.Features;
featureCollection.Add(new Guid(featureGUID), true); // true to force activation
web.Update();
}
...
does nothing. Is there some way I can "refresh" the SPWeb object so that the new list template can be seen and used?
The workaround I have found, for now, is to add the "Custom Access List" list template feature as an activation dependency in the "parent" feature receiver itself, and to make the "Custom Access List" list template feature hidden. That way, to my knowledge, the custom list definition feature is forcibly activated and I find that web.ListTemplates["Custom Access List"]; is found.
But I would much rather the former approach work - to activate, in my receiver code, the list definition feature and then to find it so that an instance of the list can then be created.
Andrew,
The problem is to do with internal async events and the timing of the activity. As you say if you go away and come back it works - i.e. the async event has completed. You are treating the featureCollection.Add as a synchronus method.
What you really should be doing if you need a template and a list instance created at the same time is using the XML framework for this.
Add a to your feature that has the list template, or alternatively add a new feature for the list instance and reference the FeatureID of the list template.
Andrew
You need to call EnsureListsData on the SPListCollection that you just updated.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistcollection.ensurelistsdata.aspx
Seems that the list template is not yet created. You can try to do a loop and wait to be created
using(SPWeb web = site.OpenWeb())
{
SPListTemplate listTemplate = null;
while (listTemplate == null)
{
Thread.Sleep(1000);
try
{
listTemplate = web.ListTemplates["Custom Access List"];
if (listTemplate != null)
{
// here your code
web.Lists.Add("My new custom access list", "", listTemplate);
}
}
catch
{
web = site.OpenWeb();
}
}
}