We’re have a sporadic problem with EWS mail users. In the stack trace we see
System.ArgumentException: Requested value 'GroupMailbox' was not found.'
Findings
This is the StackTrace :
at System.Enum.TryParseEnum (System.Type enumType, System.String value, Boolean ignoreCase, System.EnumResult& parseResult) <0x10087d640 + 0x0052b>
in <filename unknown>:0
at System.Enum.Parse (System.Type enumType, System.String value, Boolean ignoreCase) <0x1006b91a8 + 0x00057>
in <filename unknown>:0
at Microsoft.Exchange.WebServices.Data.EwsUtilities.Parse[T] (System.String value) <0x10114e1ac + 0x000e3>
in <filename unknown>:0
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.ReadValue[T] () <0x10114e764 + 0x00053>
in <filename unknown>:0
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.ReadElementValue[T] () <0x10114e078 + 0x00087>
in <filename unknown>:0
at Microsoft.Exchange.WebServices.Data.EmailAddress.TryReadElementFromXml (Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader reader) <0x1010a4330 + 0x00187>
at Microsoft.Exchange.WebServices.Data.EmailAddress.TryReadElementFromXml (Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader reader) <0x1010a4330 + 0x00187>
In the source we thing this method
EmailAddress :: TryReadElementFromXml
case XmlElementNames.MailboxType:
this.mailboxType = reader.ReadElementValue<MailboxType>();
Analysis:
We believe that for some messages a MailboxType enum is trying to be parsed. However the enum MailboxType does not contain the value GroupMailbox and therefore throws an exception.
This is the documentation for the MailboxType enum
https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.mailboxtype%28v=exchg.80%29.aspx?f=255&MSPPError=-2147217396
Is it possible that the server logic was updated on the enum was not kept up-to-date???
Furthermore:
Also we’ve traced it down to the method in EWSUtilities.cs
internal static T Parse<T>(string value)
The else clause is
else
{
return (T)Enum.Parse(typeof(T), value, false);
}
Which should be reserved for when the enumeration is not found??? And instead of doing a TryParse its doing a Parse which fails.
This apparently is also a bug???
The Source for the EWS Managed API is on GitHub and I believe this has been updated with then new Enum https://github.com/OfficeDev/ews-managed-api/blob/154dbc66ac018d861c73ce489839cd9f58a1b0cd/Enumerations/MailboxType.cs . You should be compiling and using the latest source from GitHub as the latest release version and NuGet version released predates the change. (Microsoft should really be updating NuGet package to avoid issues).
Related
In my logs, I found a weird error regarding my ServiceStack service. I don't have further information than the following stacktrace and I didn't manage to reproduce the error yet. That's the stacktrace:
JsvTypeSerializer.EatMapKey (ServiceStack.Text.StringSegment value, System.Int32& i)
DeserializeDictionary`1[TSerializer].ParseStringDictionary (ServiceStack.Text.StringSegment value)
(wrapper delegate-invoke) :invoke_object_StringSegment (ServiceStack.Text.StringSegment)
JsvReader`1[T].ParseStringSegment (ServiceStack.Text.StringSegment value)
JsvReader`1[T].Parse (System.String value)
TypeSerializer.DeserializeFromString[T] (System.String value)
StringExtensions.FromJsv[T] (System.String jsv)
WebServiceException.ParseResponseDto ()
WebServiceException.get_ErrorMessage ()
WebServiceException.get_Message ()
I'm not sure where I should start, the service actually only has json enabled and not jsv, and the part where I handle the request is inside a try-catch block, so I'm not sure why the error is actually happening.
This Exception is due to not being able to parse a structured Error ResponseStatus thrown in a WebServiceException possibly due to returning an unknown Error Response. I've made it so this parsing heuristic doesn't throw an Exception when it fails in this commit.
This change is available from v5.0.3 that's now available on MyGet.
I have one simply question: Is it possible to parse F# Map type from json? Because when I try it (With F# Map<string, string>), it is easy to serialize and it looks how it have to, but when I try to deserialize it is throwing an exception.
Newtonsoft.Json.JsonSerializationException: Unable to find a default constructor to use for type Microsoft.FSharp.Collections.FSharpMap`2[System.Int32,System.String]. Path '1', line 2, position 7.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewDictionary (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, System.Boolean& createdFromNonDefaultConstructor) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <filename unknown>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0
And it is deserializing from classic:
Map.ofList [ ("1", "one"); ("2", "two"); ("3", "three") ]
The resulting JSON looks like C# dictionary
{
"1": "one",
"2": "two",
"3": "three"
}
It is serializing without settings (Only indentation). So is it possible to serialize this, or is there some working workaround?
Thanks for answer
You can make your own converter to do this. It's a lot of reflection and constructing appropriate generic types, but it can be done.
You first deserialize to a Dictionary<Key, Val>, then create and fill a List<Tuple<Key, Val>> manually via reflection (because the Map constructor requires Tuples, not KeyValuePairs), then finally pass that into the Map constructor.
Not sure if there's an easier way, but this is what I came up with:
open System
open System.Collections
open System.Collections.Generic
open Newtonsoft.Json
let mapConverter = {
new JsonConverter() with
override x.CanConvert(t:Type) =
t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<Map<_, _>>
override x.WriteJson(writer, value, serializer) =
serializer.Serialize(writer, value)
override x.ReadJson(reader, t, _, serializer) =
let genArgs = t.GetGenericArguments()
let generify (t:Type) = t.MakeGenericType genArgs
let tupleType = generify typedefof<Tuple<_, _>>
let listType = typedefof<List<_>>.MakeGenericType tupleType
let create (t:Type) types = (t.GetConstructor types).Invoke
let list = create listType [||] [||] :?> IList
let kvpType = generify typedefof<KeyValuePair<_, _>>
for kvp in serializer.Deserialize(reader, generify typedefof<Dictionary<_, _>>) :?> IEnumerable do
let get name = (kvpType.GetProperty name).GetValue(kvp, null)
list.Add (create tupleType genArgs [|get "Key"; get "Value"|]) |> ignore
create (generify typedefof<Map<_, _>>) [|listType|] [|list|]
}
Once you have your converter, then you just pass it into the DeserializeObject method and JsonConvert will use it wherever appropriate.
let str = JsonConvert.SerializeObject (Map<_, _> [333, 1234])
JsonConvert.DeserializeObject<Map<int, int>>(str, mapConverter)
The nice thing about doing it this way is that if you've got a big/deep record where your Map is just a single field, then it'll work with that too--you don't have to go changing your record structure to use Dictionaries just to support serialization.
This functionality became part of JSON.Net in version 6.0.3. (April 30th, 2014)
But, if you are stuck for some reason using an earlier version then a simplified (and more efficient as less reflection) version of Dax Fohl's version could be:
type mapConvert<'f,'t when 'f : comparison>() =
static member readJson (reader:JsonReader, serializer:JsonSerializer) =
serializer.Deserialize<Dictionary<'f, 't>> (reader)
|> Seq.map (fun kv -> kv.Key, kv.Value)
|> Map.ofSeq
let mapConverter = {
new JsonConverter() with
override __.CanConvert (t:Type) =
t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<Map<_, _>>
override __.WriteJson (writer, value, serializer) =
serializer.Serialize(writer, value)
override __.ReadJson (reader, t, _, serializer) =
let converter =
typedefof<mapConvert<_,_>>.MakeGenericType (t.GetGenericArguments())
let readJson =
converter.GetMethod("readJson")
readJson.Invoke(null, [| reader; serializer |])
}
The problem is that json.net can't construct a Map<int,string>. However if you deserialize to a regular .net Dictionary<int,string> it will work, as the json is the same.
You can't serialize F#'s Map directly, since it has no default contructor (constructor with no parameter) at all.
This is the original documentation of F# map: (from http://msdn.microsoft.com/en-us/library/ee353686%28v=vs.110%29.aspx)
[<Sealed>]
type Map<[<EqualityConditionalOnAttribute>] 'Key,[<ComparisonConditionalOnAttribute>] [<EqualityConditionalOnAttribute>] 'Value (requires comparison)> =
class
interface IEnumerable
interface IComparable
interface IEnumerable
interface ICollection
interface IDictionary
new Map : seq<'Key * 'Value> -> Map< 'Key, 'Value>
member this.Add : 'Key * 'Value -> Map<'Key, 'Value>
member this.ContainsKey : 'Key -> bool
member this.Remove : 'Key -> Map<'Key, 'Value>
member this.TryFind : 'Key -> 'Value option
member this.Count : int
member this.IsEmpty : bool
member this.Item ('Key) : 'Value
end
As you see above, Map doesn't have default constructor but the serializer need a class with default constructor.
The best way to serialize a map is mapping the map to be regular .NET dictionary, but then the new dictionary doesn't have all of the advantages of F#'s Map, especially the immutability of F#'s Map.
I'm testing out MvvmCross in an existing Monotouch project.
I would like to start migrating the project to Mvvm in pieces.
I can start the application and it shows my first (mvvm) screen.
After that, i'm doing different (non mvvmcross) things (loading views etc) which I would like to port on a later moment.
I was now trying to port one of my views also to mvvmcross.
I created a View "public class TestView : MvxViewController" and a ViewModel "public class TestViewModel : MvxViewModel"
When loading that View, the app crashed with following error:
---Message:
Object reference not set to an instance of an object
---Stack Trace:
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.Touch.Views.MvxViewControllerExtensionMethods+<OnViewCreate>c__AnonStorey3.<>m__9 () [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__this___object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Touch.Views.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 CatalogMVVMTest.Touch.Views.TestView.ViewDidLoad () [0x0001a] in /Users/matthiasvalcke/Projects/MVVMDemos/CatalogMVVMTest/CatalogMVVMTest.Touch/Views/TestView.cs:20
...
It seems it crashes when calling "base.ViewDidLoad ();"
Not sure if this is important, but after loading the first view, I'm loading a new (non mvvmcross) view as root of the navigation stack.
So now I'm trying to load a MvvmCross View to a normal UIView(Controller)
I'm also getting following Mvx diagnostic output:
mvx: Diagnostic: 1.08 Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction
edit:
I'm also getting it if I just edit a simple sample from MvvmCross. For example, if I just take the basic sample with one "FirstView" and "FirstViewModel" and I do something like this, I'm getting the error:
var secondv = new SecondView ();
secondv.View.Frame = new RectangleF (0,250,320,100);
Add (secondv.View);
SecondView is just a MvxViewController. It seems like I can not add a View from a MvxViewController to another MvxViewController in code. Is this correct?
Anyone having an idea?
Ok, instead of doing this:
var secondv = new SecondView (); //(this is a MvxViewController
secondv.View.Frame = new RectangleF (0,250,320,100);
Add (secondv.View);
I had to do this (i found it in the tabbar sample):
var viewModel = new SecondViewModel ();
var secondv = this.CreateViewControllerFor(viewModel) as UIViewController;
secondv.View.Frame = new RectangleF (0,250,320,10);
secondv.View.AutoresizingMask = UIViewAutoresizing.None; //was needed because mvvm is enabling autostretch automatically?
Add (secondv.View);
Sorry for the questions, I'm using a lot of UIViewControllers on other UIViewControllers and it's difficult to understand the complete MvvmCross framework :-)
I'm still getting following diagnostic output, but no nullpointer anymore and it works:
mvx: Diagnostic: 0.11 Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction
Thanks for the help!
You are most likely hitting a bug in Xamarin's latest release.
This was addressed in https://github.com/slodge/MvvmCross/commit/5786d4964e4262cbf91661f04427e19648acf7df
Try upgrading to the mvvmcross 3.0.11-beta1 release or later - or roll back your xamarin version.
More info on http://forums.xamarin.com/discussion/comment/26049/#Comment_26049
I'm getting some of those exceptions below. What are my options to track those issues down? I'm kind of lost with those as they happen sporadically only and ONLY on the device but never in the Simulator.
System.Exception: Selector invoked from objective-c on a managed object that has been GC'ed ---> System.MissingMethodException: No constructor found for Browser.FolderListController::.ctor(System.IntPtr)
at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at MonoTouch.ObjCRuntime.Runtime.ConstructNSObject (IntPtr ptr, IntPtr klass) [0x00000] in <filename unknown>:0
at MonoTouch.ObjCRuntime.Runtime.GetNSObject (IntPtr ptr) [0x00000] in <filename unknown>:0
at MonoTouch.ObjCRuntime.Runtime.GetNSObjectWrapped (IntPtr ptr) [0x00000] in <filename unknown>:0
at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetNSObjectWrapped (intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0
at Browser.Application.Main (System.String[] args) [0x00000] in .../Main.cs:15
This isn't exactly related to the OP's situation, but I got this error when loading a view from a nib and it turned out I hadn't setup the view class's constructor properly:
public MyView() : base()
{
// Wrong!
}
You need to include the IntPtr parameter:
public MyView(IntPtr handle) : base(handle)
{
}
There's not a single, simple answer to that but I can share a way to help hunting them done:
Like #Miguel said such an exception means that the runtime is trying to re-surface an instance of Browser.FolderListController. That means that one, or many, instance(s) of Browser.FolderListController are being collected even if they will still be needed later.
Your first step should be to review the life cycle of every Browser.FolderListController instances. E.g.
where they are created;
where the calls occurs;
where you Dispose them manually - which can conflict with any retain'ing MonoTouch try to do to help your;
null'ed or removed from collections (i.e. removing references)...
Once you know the lifecycle you can:
add a finalizer to Browser.FolderListController and set a breakpoint inside it. The finalizer are executed on a separate thread so it won't tell you where the last reference was removed - but it will tell you approximately when (at least not before some point);
add the .ctor(IntPtr) constructor and add a breakpoint inside it. Again it won't give you an exact point (where it's being required) but it will tell you approximately when (at least not before another point);
Execute your application, get the crash and then look at what's going on between between those two points in time (compared to your lifecycle).
The above means that an object was created, passed down to Objective-C to be kept around and then it was garbage collected by Mono, and later re-surfaced to Mono on either a callback or some delegate invocation.
This usually means that in our code, we failed to catch a case where we needed to keep an explicit reference. A test case for this would be useful as it would help us fix this in MonoTouch.
We have also developed a new technique to eliminate all of these problems at once, but the code is not ready for public use.
I get this exception every time i try to create a new Iphone/Ipad solution?
I have been following the guides and have both XCode, interface builder and IOS SDK installed.
Any clues are welcome:)
System.ApplicationException: Can't create display binding for mime type: application/vnd.apple-interface-builder
at MonoDevelop.Ide.Gui.Workbench.NewDocument (System.String defaultName, System.String mimeType, System.IO.Stream content) [0x00000] in :0
at MonoDevelop.Ide.Templates.FileTemplate.CreateFile (MonoDevelop.Ide.Templates.FileDescriptionTemplate newfile, MonoDevelop.Projects.SolutionItem policyParent, MonoDevelop.Projects.Project project, System.String directory, System.String language, System.String name) [0x00000] in :0
at MonoDevelop.Ide.Templates.FileTemplate.Create (MonoDevelop.Projects.SolutionItem policyParent, MonoDevelop.Projects.Project project, System.String directory, System.String language, System.String name) [0x00000] in :0
at MonoDevelop.Ide.Projects.NewFileDialog.OpenEvent (System.Object sender, System.EventArgs e) [0x00000] in :0
It appears that you are trying to create a new file, not a new project/solution.