MVVMCross + Xamarin + WCF Data Services 5.6 = Not Implemented Exception? - xamarin.android

I'm using WCF Data Services 5.6 in a PCL project with MVVMCross. In the WPF client the following code (in the viewModel) works like a charm (based on the sample found at http://msdn.microsoft.com/en-us/library/dd756367(v=vs.110).aspx):
DataServiceQuery<T> query = this.LoadItemsQuery;
query.BeginExecute((result) =>
{
try
{
DataServiceQuery<T> resultQuery = result.AsyncState as DataServiceQuery<T>;
foreach (T item in resultQuery.EndExecute(result))
{
// Do something here
}
}
catch (Exception ex)
{
PublishException(ex);
}
}
, query);
But in the Android client, "resultQuery.EndExecute(result)" throws the following exception:
System.InvalidOperationException: An error occurred while processing this request. ---> System.NotImplementedException: The requested feature is not implemented.
at System.Net.WebResponse.get_SupportsHeaders () [0x00000] in <filename unknown>:0
at System.Data.Services.Client.HttpWebRequestMessage.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.ODataRequestMessageWrapper.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.DataServiceContext.GetResponseHelper (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult, Boolean handleWebException) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.DataServiceContext.EndGetResponse (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.RequestInfo.EndGetResponse (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Data.Services.Client.BaseAsyncResult.EndExecute[QueryResult] (System.Object source, System.String method, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.QueryResult.EndExecuteQuery[Appointment] (System.Object source, System.String method, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 }
Any ideas? Has someone tested WCF Data Services 5.6 with MonoDroid?
Thanks in advance

https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/WebResponse.cs
You can see from the source code that it is indeed not implemented.
Mono's WCF support is not complete, so using it against WCF Data Services is risky.
If possible, use ASP.NET Web API instead of WCF at server side, and then on client side you get better support via HttpClient.

The bug is in HttpWebResponse.cs,which should add the following:
public override bool SupportsHeaders
{
get
{
return true;
}
}

Should work with the latest release : Mono for Android 4.12.3.I test and found it worked with Microsoft.Data.Service.Client.Portable.dll.

Related

Cannot get MvvmCross using storyboards in iOS to work

I am trying to write an MvvmCross app using StoryBoards. I know there are similar questions, but I have followed the solutions and I cannot get it to work. I have referenced one of the solutions I have tried in this question.
I'll explain what I have done from the beginning, hopefully this will help in the diagnosis of my problem
Create a project using the the Universal iOS Single View App in Visual Studio.
I do the standard MvvmCross setup, adding nuget, updating AppDelegate etc.
I get it to compile.
I add a new ViewController to the iPhone storyboard. I call it LogonViewController. I set the Class, Storyboard ID and Restoration ID to LogonViewController. The LogonViewController class is generated. I change it to derive it from MvxViewController
I move the entry arrow from the RootViewController (the view controller on the storyboard when it was initially created) to point to the LogonViewController. I leave the RootViewController on the storyboard
I Change the LogonViewController class to derive from MvxViewController and set the Register attribute to LogonView eg
[Register ("LogonView")]
partial class LogonViewController
I add a label to the LogonViewController just as something to display.
I create a custom container derived from MvxTouchViewsContainers as per the post in
MVVMCross support for Xamarin.iOS Storyboards
The problem is that when the overridden method (shown below) is called in the custom container I get An invalid cast exception as it cannot cast a UIKit.UIViewController to a IMvxTouchView
I also get an arithmetic overflow exception
protected override IMvxTouchView CreateViewOfType(Type viewType, MvxViewModelRequest request)
{
return (IMvxTouchView)UIStoryboard.FromName("MyStoryBoard", null)
.InstantiateViewController(viewType.Name);
}
In the trace log I get the following errors
2015-01-28 18:12:09.833 MyApp[3743:68927] mvx:Diagnostic: 8.61 Setup: LastChance start
[0:] mvx:Diagnostic: 8.61 Setup: LastChance start
[0:]
2015-01-28 18:12:10.247 MyApp[3743:68927] mvx:Diagnostic: 9.05 Setup: Secondary end
[0:] mvx:Diagnostic: 9.05 Setup: Secondary end
[0:]
2015-01-28 18:12:10.647 MyApp[3743:68927] mvx:Diagnostic: 9.43 Showing ViewModel LogonViewModel
[0:] mvx:Diagnostic: 9.43 Showing ViewModel LogonViewModel
[0:]
2015-01-28 18:12:11.049 MyApp[3743:68927] TouchNavigation:Diagnostic: 9.83 Navigate requested
[0:] TouchNavigation:Diagnostic: 9.83 Navigate requested
2015-01-28 18:12:11.254 MyApp[3743:68927] Unknown class LogonViewController in Interface Builder file.
2015-01-28 18:12:23.962 MyApp[3743:68927] -[UIViewController bottomLayoutGuide]: guide not available before the view controller's view is loaded
System.OverflowException: Arithmetic operation resulted in an overflow.
at Mono.Debugging.Soft.SoftDebuggerAdaptor.TargetObjectToObject(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValueImpl(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValue(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
System.OverflowException: Arithmetic operation resulted in an overflow.
at Mono.Debugging.Soft.SoftDebuggerAdaptor.TargetObjectToObject(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValueImpl(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValue(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
System.OverflowException: Arithmetic operation resulted in an overflow.
at Mono.Debugging.Soft.SoftDebuggerAdaptor.TargetObjectToObject(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext ctx, Object obj)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValueImpl(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
at Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValue(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags)
Unhandled Exception:
System.InvalidCastException: Unable to cast object of type 'UIKit.UIViewController' to type 'Cirrious.MvvmCross.Touch.Views.IMvxTouchView'.
I'm at a loss to know what I am doing wrong here. Has anyone got any ideas? This is the versions of software installed
MvvmCross 3.5.0
Visual Studio 2012 Update 4,
Xamarin Universal Installer v3.5.0.0
Xamarin Studio 5.7 v5.7.0.661
Xamarin v3.9.236.0
Update
I took EShy's advice and added the controller and named it LogonView, however I still get a problem where the LogonViewModel is not getting contructed. The log is shown below. Any ideas?
2015-01-29 11:31:33.579 MyApp[12631:273902] mvx:Diagnostic:286.77 Message = [Failed to construct and initialize ViewModel for type MyApp.Core.ViewModels.LogonViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information]
[0:] mvx:Diagnostic:286.77 Message = [Failed to construct and initialize ViewModel for type MyApp.Core.ViewModels.LogonViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information]
[0:]
2015-01-29 11:31:33.985 MyApp[12631:273902] mvx:Diagnostic:287.17 Stack Trace = [ at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled
[0:] mvx:Diagnostic:287.17 Stack Trace = [ at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
at (wrapper delegate-invoke) <Module>:invoke_void_object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
at MyApp.iOS.Application.Main (System.String[] args) [0x00002] in c:\MyApp.iOS\Main.cs:21 ]
(System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
at (wrapper delegate-invoke) <Module>:invoke_void_object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
at MyApp.iOS.Application.Main (System.String[] args) [0x00002] in c:\MyApp\
MyApp.iOS\Main.cs:21 ]
[0:]
2015-01-29 11:31:34.393 MyApp[12631:273902] mvx:Diagnostic:287.58 Inner Exception message = [Problem creating viewModel of type LogonViewModel]
[0:] mvx:Diagnostic:287.58 Inner Exception message = [Problem creating viewModel of type LogonViewModel]
You should name your viewcontroller in the storyboard LogonView and not LogonViewController. That's the viewType.Name that MvvmCross is looking for.
The problem was that a service injected into the LogonViewModel used the MvvmCross Messenger plugin. I had not added the plugin via nuget to the project. The exception that informed me of this was an inner exception of an inner exception. I should have dug deeper. Thanks again to you Stuart for this help and MvvmCross goodness in general. Thanks also to EShy for the naming help.

Exception when run Aspnet Mvc app on OS X

I'm trying to run samples for aspnet 5 on os x:
git clone https://github.com/shirhatti/Home.git
When I build the project HelloMvc -- 'kpm build' -- it's ok.
Then I run app using 'k kestrel' and see the following error:
Missing method Microsoft.Framework.Runtime.ILibraryInformation::get_LoadableAssemblies() in assembly data-0x7feb6aa02a00, referenced in assembly /Users/minya/.kpm/packages/Microsoft.AspNet.Mvc.Core/6.0.0-beta2-11905/lib/aspnet50/Microsoft.AspNet.Mvc.Core.dll
System.MissingMethodException: Method not found: 'Microsoft.Framework.Runtime.ILibraryInformation.get_LoadableAssemblies'.
at System.Linq.Enumerable+c__Iterator122[Microsoft.Framework.Runtime.ILibraryInformation,System.Reflection.AssemblyName].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator102[System.Reflection.AssemblyName,System.Reflection.Assembly].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator122[System.Reflection.Assembly,System.Reflection.TypeInfo].MoveNext () [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.BuildModel () [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.GetDescriptors () [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.Invoke (Microsoft.AspNet.Mvc.ActionDescriptorProviderContext context, System.Action callNext) [0x00000] in <filename unknown>:0
at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1+CallNext[Microsoft.AspNet.Mvc.ActionDescriptorProviderContext].CallNextProvider () [0x00000] in :0
at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1[Microsoft.AspNet.Mvc.ActionDescriptorProviderContext].Invoke (Microsoft.AspNet.Mvc.ActionDescriptorProviderContext context) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.GetCollection () [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors () [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.GetActionDescriptors (IServiceProvider services) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.CreateAttributeMegaRoute (IRouter target, IServiceProvider services) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc (IApplicationBuilder app, System.Action1 configureRoutes) [0x00000] in :0
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc (IApplicationBuilder app) [0x00000] in :0
at KWebStartup.Startup.Configure (IApplicationBuilder app) [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
There is no exact problem in google. I was tried to reinstall kvm, delete and checkout NuGet deps.
Updated:
Similar behavior on Windows when I try to run the same project by 'k web':
System.MissingMethodException: Method not found: 'System.Collections.Generic.IEnumerable1<System.Reflection.AssemblyName> Microsoft.Framework.Runtime.ILibraryInformation.g
et_LoadableAssemblies()'.
at Microsoft.AspNet.Mvc.DefaultAssemblyProvider.<>c__DisplayClass0.<get_CandidateAssemblies>b__1(ILibraryInformation l)
at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.BuildModel()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNet.Mvc.ControllerActionDescriptorProvider.Invoke(ActionDescriptorProviderContext context, Action callNext)
at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1.CallNext.CallNextProvider()
at Microsoft.Framework.DependencyInjection.NestedProviders.NestedProviderManager1.Invoke(T context)
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.GetCollection()
at Microsoft.AspNet.Mvc.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.GetActionDescriptors(IServiceProvider services)
at Microsoft.AspNet.Mvc.Routing.AttributeRouting.CreateAttributeMegaRoute(IRouter target, IServiceProvider services)
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder app, Action1 configureRoutes)
at Microsoft.AspNet.Builder.BuilderExtensions.UseMvc(IApplicationBuilder app)
at HelloMvc.Startup.Configure(IApplicationBuilder app) in C:\prj\Home\samples\HelloMvc\Startup.cs:line 18
Seems to be the problem is in one (or more) of referenced in Microsoft.AspNet.Mvc.* assemblies. This is disassemble of DefaultAssemblyProvider from Microsoft.AspNet.Mvc.Core. I guess the problem is in ILibraryManager's implementations GetReferencingLibraries() method. But I can't find this implementation.
public class DefaultAssemblyProvider : IAssemblyProvider
{
private static readonly HashSet<string> _mvcAssemblyList;
private readonly ILibraryManager _libraryManager;
public IEnumerable<Assembly> CandidateAssemblies
{
get
{
return Enumerable.Select<AssemblyName, Assembly>(Enumerable.SelectMany<ILibraryInformation, AssemblyName>(this.GetCandidateLibraries(), DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate2 ?? (DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__CachedAnonymousMethodDelegate2 = new Func<ILibraryInformation, IEnumerable<AssemblyName>>(DefaultAssemblyProvider.\u003C\u003Ec__DisplayClass0.CS\u0024\u003C\u003E9__inst.\u003Cget_CandidateAssemblies\u003Eb__1))), new Func<AssemblyName, Assembly>(DefaultAssemblyProvider.Load));
}
}
static DefaultAssemblyProvider()
{
HashSet<string> hashSet = new HashSet<string>((IEqualityComparer<string>) StringComparer.Ordinal);
string str1 = "Microsoft.AspNet.Mvc";
hashSet.Add(str1);
string str2 = "Microsoft.AspNet.Mvc.Core";
hashSet.Add(str2);
string str3 = "Microsoft.AspNet.Mvc.ModelBinding";
hashSet.Add(str3);
string str4 = "Microsoft.AspNet.Mvc.Razor";
hashSet.Add(str4);
string str5 = "Microsoft.AspNet.Mvc.Razor.Host";
hashSet.Add(str5);
string str6 = "Microsoft.AspNet.Mvc.Rendering";
hashSet.Add(str6);
DefaultAssemblyProvider._mvcAssemblyList = hashSet;
}
public DefaultAssemblyProvider(ILibraryManager libraryManager)
{
this._libraryManager = libraryManager;
}
internal IEnumerable<ILibraryInformation> GetCandidateLibraries()
{
return Enumerable.Where<ILibraryInformation>(Enumerable.Distinct<ILibraryInformation>(Enumerable.SelectMany<string, ILibraryInformation>((IEnumerable<string>) DefaultAssemblyProvider._mvcAssemblyList, new Func<string, IEnumerable<ILibraryInformation>>(this._libraryManager.GetReferencingLibraries))), new Func<ILibraryInformation, bool>(DefaultAssemblyProvider.IsCandidateLibrary));
}
private static Assembly Load(AssemblyName assemblyName)
{
return Assembly.Load(assemblyName);
}
private static bool IsCandidateLibrary(ILibraryInformation library)
{
return !DefaultAssemblyProvider._mvcAssemblyList.Contains(library.get_Name());
}
}
I had a similar problem on Windows and found the wrong KRE was active.
Executing kvm list shows a list of KRE. In my case the 1.0.0-alpha4 version was active instead of the more recent beta version.
Switching to the default with kvm use default sorted it out for me.
I was able to resolve this error by updating my version of KVM, there is probably a simpler way but, assuming you initially installed using homebrew, running these commands should solve your issue
brew untap aspnet/k
brew tap aspnet/k
brew install kvm
then you should be able to run k kestrel
if you get a message that kvm is already installed then:
brew link --overwrite mono
brew uninstall mono
brew reinstall kvm

Why does adding a Header view to a MvxListView derivative disrupt the binding process?

I'm currently using MvvmCross for new app projects, and I'm trying to display a header view with a MvxListView. Reading discussions such as this has led me to understand that a headerview cannot be added after the adapter has been set, so the constructor must be overridden so that the header is added before the MvxAdapter is set. This has led me to implement the following class:
public class HeaderListView : MvxListView
{
public FrameLayout HeaderFrame { get; set; }
public HeaderListView(Context context, IAttributeSet attrs)
: this(context, attrs, new MvxAdapter(context))
{
}
public HeaderListView(Context context, IAttributeSet attrs, IMvxAdapter adapter)
: base(context, attrs, null)
{
InitializeHeader(context);
// Note: Any calling derived class passing a null adapter is responsible for setting
// it's own itemTemplateId
if (adapter == null)
return;
var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
adapter.ItemTemplateId = itemTemplateId;
Adapter = adapter;
}
private void InitializeHeader(Context context)
{
HeaderFrame = new FrameLayout(context);
AddHeaderView(HeaderFrame);
}
}
Pay particular attention to the InitializeHeader call in the second constructor. When I comment this line out, the test application starts up fine and this HeaderListView behaves indistinguishably from a standard MvxListView. However, uncomment that line and you are greeted with a blank ListView and a number of binding errors:
MvxBind:Error: 10.86 Problem seen during binding execution for binding ItemsSource for Names - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
02-02 23:33:01.948 I/mono-stdout( 2323): MvxBind:Error: 10.86 Problem seen during binding execution for binding ItemsSource for Names - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.948 I/mono-stdout( 2323): at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
02-02 23:33:01.948 I/mono-stdout( 2323): at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
02-02 23:33:01.958 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00000] in <filename unknown>:0
InnerException was NullReferenceException: Object reference not set to an instance of an object
at Cirrious.MvvmCross.Binding.Droid.Views.MvxListView.set_ItemsSource (IEnumerable value) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
02-02 23:33:01.958 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): InnerException was NullReferenceException: Object reference not set to an instance of an object
02-02 23:33:01.968 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Droid.Views.MvxListView.set_ItemsSource (IEnumerable value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
I can't make any sense at all of this error, because the only difference that causes its appearance is that I assign a header view before assigning the adapter, but that has nothing whatsoever to do with the adapter. What is the source of this error, and how can I work around it?
The full source of my sample project demonstrating this problem is available on github.
The reason has to do with the hacky way that headers and footers were added to ListView. When you add a header or footer to a ListView, when you set the adapter for the list view, it wraps your adapter in a HeaderViewListAdapter that returns the headers and footers as though they were just rows before and after the actual rows your adapter returns.
The reason this fails with MvxListView is its Adpater property which looks like this:
public new IMvxAdapter Adapter
{
get { return base.Adapter as IMvxAdapter; }
set
{
// Code to copy ItemsSource and template ID
base.Adapter = value;
}
}
It does not store the IMvxAdapter instance you give it. It just sets it in the base.Adapter and expects when it gets base.Adapter later it will be the same value it set earlier. But that is not true when headers and footers are added to the list. The class you get back from base.Adapter will be a HeaderViewListAdapter that wraps the instance of IMvxAdapter that was set earlier.
There is no good way to work around this as a user of MvxList (other than copy and change MvxList). The fix for Stuart would be to not rely on base.Adapter for the getter, but instead store the value into a field in the setter and return that from the getter.
By adding ItemsSource in the .axml file causes the List to set an Adapter and you can not add a header/footer to a listview when an Adapter is set.
I had a similar issue and ended using
MvxListWithHeader - It allows you to add a header and footer to a MvxListView.
I can't see any obvious reason behind the error.
It doesn't look like the "binding process" is being disrupted from your trace. Instead it looks like the Adapter is somehow being stuck at null.
One suggestion to help debug further - if you add a new ItemsSource to your custom list view, then this will be used for binding - and will give you a place to put a breakpoint so that you can investigate the state of the ListView control during the set_ItemsSource null reference problem.
[MvxSetToNullAfterBinding]
public new IEnumerable ItemsSource
{
get { return Adapter.ItemsSource; }
set {
// here is where null is being reported
// add a breakpoint and examine Adapter and ((ListView)this).Adapter in the watch window
Adapter.ItemsSource = value;
}
}
Beyond this, you could try copying all the MvxListView code into your view to see if that helps identify the issue.

failed to find constructor for type MvxViewModelLoader MvvmCross IOS

I use MvvmCross for develop a CrossPlatform App.
I work on my Mac and I have not errors when I build my solution.
When I run it... I have this error : failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader and highlights base.ViewDidLoad();
Code :
public partial class MainView : MvxViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public MainView ()
: base (UserInterfaceIdiomIsPhone ? "MainView_iPhone" : "MainView_iPad", null)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
}
It's a default code, I just changed super-class (UIViewController to MvxViewController)
Stacktrace :
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingResolver.Resolve () [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, ResolveOptions resolveOptions, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.CrossCore.Mvx.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods+<>c_DisplayClass1.b_0 () [0x00000] in :0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in :0
at (wrapper delegate-invoke) :invoke_void_this__object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in :0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in :0
at TrainingCatalog.Touch.MainView.ViewDidLoad () [0x00002] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Views/MainView.cs:30
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129
at TrainingCatalog.Touch.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0003c] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/AppDelegate.cs:21
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIApplication.cs:38
at TrainingCatalog.Touch.Application.Main (System.String[] args) [0x00008] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Main.cs:17
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
From the stack trace, I'm guessing the line that is failing is: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxViewControllerExtensionMethods.cs#L44
This is looking in IoC for a type which has been registered in setup as:
protected virtual void InitializeViewModelFramework()
{
Mvx.RegisterType<IMvxViewModelLoader, MvxViewModelLoader>();
}
(from https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/Platform/MvxSetup.cs#L192)
Looking at MvxViewModelLoader, this is defined in: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelLoader.cs - so it should have a default public parameterless constructor added by the compiler...
With this in mind...
I'm guessing that maybe Xamarin is stripping out the constructor from your deployed binaries. This might be because of your linker settings - so please check that you have set the linker to link "SDK only". But if that doesn't help then this might be down to some Xamarin optimisation/feature - so you might need to .
As a simple workaround you could try overriding Setup so that you use:
protected override void InitializeViewModelFramework()
{
Mvx.RegisterSingleton<IMvxViewModelLoader>(() => new MvxViewModelLoader>());
}
However, even if this works, then I'd be worried that the linker might be stripping out other symbols in your app - so this might not be enough... you might need to chase this through with Xamarin.

Objective Sharpie Fails to generate binding

I am trying to create a simple binding to an enterprise library using Objective Sharpie.
It keeps failing with the following message:
Cannot be negative.
Parameter name: length
System.ArgumentOutOfRangeException: Cannot be negative.
Parameter name: length
at System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in :0
at Sharpie.ObjC.ObjCExtensions.ToGetAccessorSelectorFromSetAccessor (System.String selector) [0x00000] in :0
at Sharpie.ObjC.CodeDomMassager.MassageMethod (Sharpie.CodeDom.TypeDeclaration type, Sharpie.CodeDom.MethodDeclaration method) [0x00000] in :0
at Sharpie.ObjC.CodeDomMassager.MassageTypeMembers[MethodDeclaration] (Sharpie.CodeDom.TypeDeclaration type, System.Action2 massager) [0x00000] in <filename unknown>:0
at Sharpie.ObjC.CodeDomMassager.MassageType (Sharpie.CodeDom.TypeDeclaration type) [0x00000] in <filename unknown>:0
at Sharpie.ObjC.CodeDomMassager.MassageAll () [0x00000] in <filename unknown>:0
at Sharpie.ObjC.Parser.Parse (System.IO.TextWriter sexpWriter, System.Collections.Generic.List1 stderrLines) [0x00000] in :0
at Sharpie.Mac.MainWindowController+c_AnonStorey3.<>m_B (System.Object o) [0x00000] in :0
From other answers I found that there might be a problem with accessors but I don't find
(void)get
or
(void)set
in my code. Help!

Resources