} else {
var typeHandleValue = Type.GetTypeHandle (memberValue);
var isDeclaredType = typeHandleValue.Equals (CodeInterpreter.ConvertValue (memberValue, memberType, Globals.TypeOfObject));
- if (isNullableOfT)
+ if (isNullableOfT) {
ctx.InternalSerialize (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
- else
- ctx.InternalSerializeReference (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
- //InternalSerialize((isNullableOfT ? XmlFormatGeneratorStatics.InternalSerializeMethod : XmlFormatGeneratorStatics.InternalSerializeReferenceMethod), () => memberValue, memberType, writeXsiType);
+ } else if (memberType == Globals.TypeOfObject) {
+ var dataContract = DataContract.GetDataContract (memberValue.GetType());
+ writer.WriteAttributeQualifiedName (Globals.XsiPrefix, DictionaryGlobals.XsiTypeLocalName, DictionaryGlobals.SchemaInstanceNamespace, dataContract.Name, dataContract.Namespace);
+ ctx.InternalSerializeReference (writer, memberValue, false, false, -1, typeHandleValue);
+ } else {
+ ctx.InternalSerializeReference (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle);
+ }
}
}
}
Assert.IsTrue (s.Contains ("<Flags>All</Flags>"));
}
}
+
+ // Bug #37116
+ [Test]
+ public void KeyPairOfAny ()
+ {
+ var dict = new Dictionary<string, object> ();
+ dict.Add ("test", new List<string> () { "test entry" });
+
+ var dcs = new DataContractSerializer (typeof(Dictionary<string, object>));
+ dcs.WriteObject (new MemoryStream (), dict);
+ // Should not throw exception.
+ }
}
}
return new EndpointAddress10 (address);
}
-#if !NET_2_1
public static XmlQualifiedName GetSchema (XmlSchemaSet xmlSchemaSet)
{
if (xmlSchemaSet == null)
xmlSchemaSet.Add (XmlSchema.Read (typeof (EndpointAddress10).Assembly.GetManifestResourceStream ("ws-addr.xsd"), null));
return new XmlQualifiedName ("EndpointReferenceType", AddressingVersion.WSAddressing10.Namespace);
}
-#endif
public EndpointAddress ToEndpointAddress ()
{
System.ServiceModel.Security/TransportSecurityBindingElementTest.cs
System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
System.ServiceModel/BasicHttpBindingTest.cs
+System.ServiceModel/Bug36080Test.cs
System.ServiceModel/CallbackBehaviorAttributeTest.cs
System.ServiceModel/ChannelFactoryTest.cs
System.ServiceModel/ChannelFactory_1Test.cs
--- /dev/null
+//
+// Author:
+// Marcos Henrich <marcos.henrich@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.ServiceModel;
+using System.ServiceModel.Description;
+using System.Threading;
+using System.ServiceModel.Channels;
+using System.Text;
+using NUnit.Framework;
+
+using MonoTests.Helpers;
+
+namespace MonoTests.System.ServiceModel
+{
+ [TestFixture]
+ public class Bug36080
+ {
+ [Test]
+ public void Bug36080Test ()
+ {
+ int port = NetworkHelpers.FindFreePort ();
+ var url = "http://localhost:" + port + "/HelloWorldService";
+
+ TransportBindingElement element = new HttpTransportBindingElement { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };
+ Binding binding = new CustomBinding(new BindingElement[]
+ {
+ new TextMessageEncodingBindingElement (MessageVersion.Default, Encoding.UTF8),
+ element
+ });
+
+#if !MOBILE
+ // Init service
+ ServiceHost serviceHost = new ServiceHost (typeof (HelloWorldServiceImpl), new Uri (url));
+ serviceHost.AddServiceEndpoint (typeof (IHelloWorldService), binding, string.Empty);
+
+ serviceHost.Open ();
+#endif
+ // In Mobile we still run this tests without any server.
+ // Issue reported in #36080 was occuring before the connections fails.
+ var wait = new ManualResetEvent (false);
+
+ Exception error = null;
+ string result = null;
+
+ try {
+ var client = new HelloWorldServiceClient (binding, new EndpointAddress(url));
+ client.SayHelloToCompleted += delegate (object o, SayHelloToCompletedEventArgs e) {
+ try {
+ error = e.Error;
+ result = e.Error == null ? e.Result : null;
+ } finally {
+ wait.Set ();
+ }
+ };
+
+ var str = "Xamarin";
+ client.SayHelloToAsync(str);
+
+ Assert.IsTrue (wait.WaitOne (TimeSpan.FromSeconds (20)), "timeout");
+#if MOBILE
+ if (error.GetType() == typeof(EndpointNotFoundException))
+ return;
+#endif
+
+ Assert.IsNull (error, "#1, inner exception: {0}", error);
+ Assert.AreEqual (str, result, "#2");
+ } finally {
+#if !MOBILE
+ serviceHost.Close ();
+#endif
+ }
+ }
+ }
+
+ public class HelloWorldServiceImpl : IHelloWorldService
+ {
+ Func<string, string> sayHelloToFunc = SayHelloTo;
+
+ static string SayHelloTo (string name)
+ {
+ return name;
+ }
+
+ public IAsyncResult BeginSayHelloTo(string name, AsyncCallback callback, object asyncState)
+ {
+ return sayHelloToFunc.BeginInvoke (name, callback, asyncState);
+ }
+
+ public string EndSayHelloTo(IAsyncResult result)
+ {
+ return sayHelloToFunc.EndInvoke(result);
+ }
+
+ public IAsyncResult BeginGetHelloData(TestXamarin4WCFService.HelloWorldData helloWorldData, AsyncCallback callback, object asyncState)
+ {
+ return null;
+ }
+
+ public TestXamarin4WCFService.HelloWorldData EndGetHelloData(IAsyncResult result)
+ {
+ return null;
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.18444
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+//
+// This code was auto-generated by SlSvcUtil, version 5.0.61118.0
+//
+namespace TestXamarin4WCFService
+{
+ using System.Runtime.Serialization;
+
+ [System.Diagnostics.DebuggerStepThroughAttribute()]
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
+ [System.Runtime.Serialization.DataContractAttribute(Name = "HelloWorldData", Namespace = "http://schemas.datacontract.org/2004/07/TestXamarin4WCFService")]
+ public partial class HelloWorldData : object
+ {
+
+ private string NameField;
+
+ private bool SayHelloField;
+
+ [System.Runtime.Serialization.DataMemberAttribute()]
+ public string Name
+ {
+ get
+ {
+ return this.NameField;
+ }
+ set
+ {
+ this.NameField = value;
+ }
+ }
+
+ [System.Runtime.Serialization.DataMemberAttribute()]
+ public bool SayHello
+ {
+ get
+ {
+ return this.SayHelloField;
+ }
+ set
+ {
+ this.SayHelloField = value;
+ }
+ }
+ }
+}
+
+
+[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IHelloWorldService")]
+public interface IHelloWorldService
+{
+
+ [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IHelloWorldService/SayHelloTo", ReplyAction="http://tempuri.org/IHelloWorldService/SayHelloToResponse")]
+ System.IAsyncResult BeginSayHelloTo(string name, System.AsyncCallback callback, object asyncState);
+
+ string EndSayHelloTo(System.IAsyncResult result);
+
+ [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IHelloWorldService/GetHelloData", ReplyAction="http://tempuri.org/IHelloWorldService/GetHelloDataResponse")]
+ System.IAsyncResult BeginGetHelloData(TestXamarin4WCFService.HelloWorldData helloWorldData, System.AsyncCallback callback, object asyncState);
+
+ TestXamarin4WCFService.HelloWorldData EndGetHelloData(System.IAsyncResult result);
+}
+
+[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+public interface IHelloWorldServiceChannel : IHelloWorldService, System.ServiceModel.IClientChannel
+{
+}
+
+[System.Diagnostics.DebuggerStepThroughAttribute()]
+[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+public partial class SayHelloToCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
+{
+
+ private object[] results;
+
+ public SayHelloToCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState)
+ {
+ this.results = results;
+ }
+
+ public string Result
+ {
+ get
+ {
+ base.RaiseExceptionIfNecessary();
+ return ((string)(this.results[0]));
+ }
+ }
+}
+
+[System.Diagnostics.DebuggerStepThroughAttribute()]
+[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+public partial class GetHelloDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
+{
+
+ private object[] results;
+
+ public GetHelloDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
+ base(exception, cancelled, userState)
+ {
+ this.results = results;
+ }
+
+ public TestXamarin4WCFService.HelloWorldData Result
+ {
+ get
+ {
+ base.RaiseExceptionIfNecessary();
+ return ((TestXamarin4WCFService.HelloWorldData)(this.results[0]));
+ }
+ }
+}
+
+[System.Diagnostics.DebuggerStepThroughAttribute()]
+[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
+public partial class HelloWorldServiceClient : System.ServiceModel.ClientBase<IHelloWorldService>, IHelloWorldService
+{
+
+ private BeginOperationDelegate onBeginSayHelloToDelegate;
+
+ private EndOperationDelegate onEndSayHelloToDelegate;
+
+ private System.Threading.SendOrPostCallback onSayHelloToCompletedDelegate;
+
+ private BeginOperationDelegate onBeginGetHelloDataDelegate;
+
+ private EndOperationDelegate onEndGetHelloDataDelegate;
+
+ private System.Threading.SendOrPostCallback onGetHelloDataCompletedDelegate;
+
+ private BeginOperationDelegate onBeginOpenDelegate;
+
+ private EndOperationDelegate onEndOpenDelegate;
+
+ private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
+
+ private BeginOperationDelegate onBeginCloseDelegate;
+
+ private EndOperationDelegate onEndCloseDelegate;
+
+ private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
+
+ public HelloWorldServiceClient()
+ {
+ }
+
+ public HelloWorldServiceClient(string endpointConfigurationName) :
+ base(endpointConfigurationName)
+ {
+ }
+
+ public HelloWorldServiceClient(string endpointConfigurationName, string remoteAddress) :
+ base(endpointConfigurationName, remoteAddress)
+ {
+ }
+
+ public HelloWorldServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
+ base(endpointConfigurationName, remoteAddress)
+ {
+ }
+
+ public HelloWorldServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
+ base(binding, remoteAddress)
+ {
+ }
+
+ public System.Net.CookieContainer CookieContainer
+ {
+ get
+ {
+ System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
+ if ((httpCookieContainerManager != null))
+ {
+ return httpCookieContainerManager.CookieContainer;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ set
+ {
+ System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
+ if ((httpCookieContainerManager != null))
+ {
+ httpCookieContainerManager.CookieContainer = value;
+ }
+ else
+ {
+ throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
+ "ookieContainerBindingElement.");
+ }
+ }
+ }
+
+ public event System.EventHandler<SayHelloToCompletedEventArgs> SayHelloToCompleted;
+
+ public event System.EventHandler<GetHelloDataCompletedEventArgs> GetHelloDataCompleted;
+
+ public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
+
+ public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+ System.IAsyncResult IHelloWorldService.BeginSayHelloTo(string name, System.AsyncCallback callback, object asyncState)
+ {
+ return base.Channel.BeginSayHelloTo(name, callback, asyncState);
+ }
+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+ string IHelloWorldService.EndSayHelloTo(System.IAsyncResult result)
+ {
+ return base.Channel.EndSayHelloTo(result);
+ }
+
+ private System.IAsyncResult OnBeginSayHelloTo(object[] inValues, System.AsyncCallback callback, object asyncState)
+ {
+ string name = ((string)(inValues[0]));
+ return ((IHelloWorldService)(this)).BeginSayHelloTo(name, callback, asyncState);
+ }
+
+ private object[] OnEndSayHelloTo(System.IAsyncResult result)
+ {
+ string retVal = ((IHelloWorldService)(this)).EndSayHelloTo(result);
+ return new object[] {
+ retVal};
+ }
+
+ private void OnSayHelloToCompleted(object state)
+ {
+ if ((this.SayHelloToCompleted != null))
+ {
+ InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
+ this.SayHelloToCompleted(this, new SayHelloToCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
+ }
+ }
+
+ public void SayHelloToAsync(string name)
+ {
+ this.SayHelloToAsync(name, null);
+ }
+
+ public void SayHelloToAsync(string name, object userState)
+ {
+ if ((this.onBeginSayHelloToDelegate == null))
+ {
+ this.onBeginSayHelloToDelegate = new BeginOperationDelegate(this.OnBeginSayHelloTo);
+ }
+ if ((this.onEndSayHelloToDelegate == null))
+ {
+ this.onEndSayHelloToDelegate = new EndOperationDelegate(this.OnEndSayHelloTo);
+ }
+ if ((this.onSayHelloToCompletedDelegate == null))
+ {
+ this.onSayHelloToCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnSayHelloToCompleted);
+ }
+ base.InvokeAsync(this.onBeginSayHelloToDelegate, new object[] {
+ name}, this.onEndSayHelloToDelegate, this.onSayHelloToCompletedDelegate, userState);
+ }
+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+ System.IAsyncResult IHelloWorldService.BeginGetHelloData(TestXamarin4WCFService.HelloWorldData helloWorldData, System.AsyncCallback callback, object asyncState)
+ {
+ return base.Channel.BeginGetHelloData(helloWorldData, callback, asyncState);
+ }
+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
+ TestXamarin4WCFService.HelloWorldData IHelloWorldService.EndGetHelloData(System.IAsyncResult result)
+ {
+ return base.Channel.EndGetHelloData(result);
+ }
+
+ private System.IAsyncResult OnBeginGetHelloData(object[] inValues, System.AsyncCallback callback, object asyncState)
+ {
+ TestXamarin4WCFService.HelloWorldData helloWorldData = ((TestXamarin4WCFService.HelloWorldData)(inValues[0]));
+ return ((IHelloWorldService)(this)).BeginGetHelloData(helloWorldData, callback, asyncState);
+ }
+
+ private object[] OnEndGetHelloData(System.IAsyncResult result)
+ {
+ TestXamarin4WCFService.HelloWorldData retVal = ((IHelloWorldService)(this)).EndGetHelloData(result);
+ return new object[] {
+ retVal};
+ }
+
+ private void OnGetHelloDataCompleted(object state)
+ {
+ if ((this.GetHelloDataCompleted != null))
+ {
+ InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
+ this.GetHelloDataCompleted(this, new GetHelloDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
+ }
+ }
+
+ public void GetHelloDataAsync(TestXamarin4WCFService.HelloWorldData helloWorldData)
+ {
+ this.GetHelloDataAsync(helloWorldData, null);
+ }
+
+ public void GetHelloDataAsync(TestXamarin4WCFService.HelloWorldData helloWorldData, object userState)
+ {
+ if ((this.onBeginGetHelloDataDelegate == null))
+ {
+ this.onBeginGetHelloDataDelegate = new BeginOperationDelegate(this.OnBeginGetHelloData);
+ }
+ if ((this.onEndGetHelloDataDelegate == null))
+ {
+ this.onEndGetHelloDataDelegate = new EndOperationDelegate(this.OnEndGetHelloData);
+ }
+ if ((this.onGetHelloDataCompletedDelegate == null))
+ {
+ this.onGetHelloDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetHelloDataCompleted);
+ }
+ base.InvokeAsync(this.onBeginGetHelloDataDelegate, new object[] {
+ helloWorldData}, this.onEndGetHelloDataDelegate, this.onGetHelloDataCompletedDelegate, userState);
+ }
+
+ private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState)
+ {
+ return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
+ }
+
+ private object[] OnEndOpen(System.IAsyncResult result)
+ {
+ ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
+ return null;
+ }
+
+ private void OnOpenCompleted(object state)
+ {
+ if ((this.OpenCompleted != null))
+ {
+ InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
+ this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
+ }
+ }
+
+ public void OpenAsync()
+ {
+ this.OpenAsync(null);
+ }
+
+ public void OpenAsync(object userState)
+ {
+ if ((this.onBeginOpenDelegate == null))
+ {
+ this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
+ }
+ if ((this.onEndOpenDelegate == null))
+ {
+ this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
+ }
+ if ((this.onOpenCompletedDelegate == null))
+ {
+ this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
+ }
+ base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
+ }
+
+ private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState)
+ {
+ return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
+ }
+
+ private object[] OnEndClose(System.IAsyncResult result)
+ {
+ ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
+ return null;
+ }
+
+ private void OnCloseCompleted(object state)
+ {
+ if ((this.CloseCompleted != null))
+ {
+ InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
+ this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
+ }
+ }
+
+ public void CloseAsync()
+ {
+ this.CloseAsync(null);
+ }
+
+ public void CloseAsync(object userState)
+ {
+ if ((this.onBeginCloseDelegate == null))
+ {
+ this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
+ }
+ if ((this.onEndCloseDelegate == null))
+ {
+ this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
+ }
+ if ((this.onCloseCompletedDelegate == null))
+ {
+ this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
+ }
+ base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
+ }
+
+ protected override IHelloWorldService CreateChannel()
+ {
+ return new HelloWorldServiceClientChannel(this);
+ }
+
+ private class HelloWorldServiceClientChannel : ChannelBase<IHelloWorldService>, IHelloWorldService
+ {
+
+ public HelloWorldServiceClientChannel(System.ServiceModel.ClientBase<IHelloWorldService> client) :
+ base(client)
+ {
+ }
+
+ public System.IAsyncResult BeginSayHelloTo(string name, System.AsyncCallback callback, object asyncState)
+ {
+ object[] _args = new object[1];
+ _args[0] = name;
+ System.IAsyncResult _result = base.BeginInvoke("SayHelloTo", _args, callback, asyncState);
+ return _result;
+ }
+
+ public string EndSayHelloTo(System.IAsyncResult result)
+ {
+ object[] _args = new object[0];
+ string _result = ((string)(base.EndInvoke("SayHelloTo", _args, result)));
+ return _result;
+ }
+
+ public System.IAsyncResult BeginGetHelloData(TestXamarin4WCFService.HelloWorldData helloWorldData, System.AsyncCallback callback, object asyncState)
+ {
+ object[] _args = new object[1];
+ _args[0] = helloWorldData;
+ System.IAsyncResult _result = base.BeginInvoke("GetHelloData", _args, callback, asyncState);
+ return _result;
+ }
+
+ public TestXamarin4WCFService.HelloWorldData EndGetHelloData(System.IAsyncResult result)
+ {
+ object[] _args = new object[0];
+ TestXamarin4WCFService.HelloWorldData _result = ((TestXamarin4WCFService.HelloWorldData)(base.EndInvoke("GetHelloData", _args, result)));
+ return _result;
+ }
+ }
+}
#pragma warning restore 649
#endregion
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- extern static int GetILOffsetFromFile (string path, int methodToken, uint methodIndex, int nativeOffset);
-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern static bool get_frame_info (int skip, bool needFileInfo, out MethodBase method,
out int iloffset, out int native_offset,
else
sb.AppendFormat ("<0x{0:x5} + 0x{1:x5}> {2}", frame.GetMethodAddress (), frame.GetNativeOffset (), unknown);
} else {
- GetFullNameForStackTrace (sb, frame.GetMethod ());
+ StackTraceHelper.GetFullNameForStackTrace (sb, frame.GetMethod ());
if (frame.GetILOffset () == -1) {
sb.AppendFormat (" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress (), frame.GetNativeOffset ());
return i != 0;
}
- // This method is also used with reflection by mono-symbolicate tool.
- // mono-symbolicate tool uses this method to check which method matches
- // the stack frame method signature.
- static void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi)
- {
- var declaringType = mi.DeclaringType;
- if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition)
- declaringType = declaringType.GetGenericTypeDefinition ();
-
- // Get generic definition
- var bindingflags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
- foreach (var m in declaringType.GetMethods (bindingflags)) {
- if (m.MetadataToken == mi.MetadataToken) {
- mi = m;
- break;
- }
- }
-
- sb.Append (declaringType.ToString ());
-
- sb.Append (".");
- sb.Append (mi.Name);
-
- if (mi.IsGenericMethod) {
- Type[] gen_params = mi.GetGenericArguments ();
- sb.Append ("[");
- for (int j = 0; j < gen_params.Length; j++) {
- if (j > 0)
- sb.Append (",");
- sb.Append (gen_params [j].Name);
- }
- sb.Append ("]");
- }
-
- ParameterInfo[] p = mi.GetParametersInternal ();
-
- sb.Append (" (");
- for (int i = 0; i < p.Length; ++i) {
- if (i > 0)
- sb.Append (", ");
-
- Type pt = p[i].ParameterType;
- if (pt.IsGenericType && ! pt.IsGenericTypeDefinition)
- pt = pt.GetGenericTypeDefinition ();
-
- if (pt.IsClass && !String.IsNullOrEmpty (pt.Namespace)) {
- sb.Append (pt.Namespace);
- sb.Append (".");
- }
- sb.Append (pt.Name);
- if (p [i].Name != null) {
- sb.Append (" ");
- sb.Append (p [i].Name);
- }
- }
- sb.Append (")");
- }
-
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
--- /dev/null
+//
+// System.Diagnostics.StackTraceHelper.cs
+//
+// Author:
+// Marcos Henrich (marcos.henrich@xamarin.com)
+//
+// Copyright (C) Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Text;
+using System.Reflection;
+
+namespace System.Diagnostics {
+
+ // This class exists so tools such as mono-symbolicate can use it directly.
+ class StackTraceHelper {
+
+ public static void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi)
+ {
+ var declaringType = mi.DeclaringType;
+ if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition)
+ declaringType = declaringType.GetGenericTypeDefinition ();
+
+ // Get generic definition
+ var bindingflags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
+ foreach (var m in declaringType.GetMethods (bindingflags)) {
+ if (m.MetadataToken == mi.MetadataToken) {
+ mi = m;
+ break;
+ }
+ }
+
+ sb.Append (declaringType.ToString ());
+
+ sb.Append (".");
+ sb.Append (mi.Name);
+
+ if (mi.IsGenericMethod) {
+ Type[] gen_params = mi.GetGenericArguments ();
+ sb.Append ("[");
+ for (int j = 0; j < gen_params.Length; j++) {
+ if (j > 0)
+ sb.Append (",");
+ sb.Append (gen_params [j].Name);
+ }
+ sb.Append ("]");
+ }
+
+ ParameterInfo[] p = mi.GetParameters ();
+
+ sb.Append (" (");
+ for (int i = 0; i < p.Length; ++i) {
+ if (i > 0)
+ sb.Append (", ");
+
+ Type pt = p[i].ParameterType;
+ if (pt.IsGenericType && ! pt.IsGenericTypeDefinition)
+ pt = pt.GetGenericTypeDefinition ();
+
+ if (pt.IsClass && !String.IsNullOrEmpty (pt.Namespace)) {
+ sb.Append (pt.Namespace);
+ sb.Append (".");
+ }
+ sb.Append (pt.Name);
+ if (p [i].Name != null) {
+ sb.Append (" ");
+ sb.Append (p [i].Name);
+ }
+ }
+ sb.Append (")");
+ }
+ }
+}
System.Diagnostics/Debugger.cs
System.Diagnostics/StackFrame.cs
System.Diagnostics/StackTrace.cs
+System.Diagnostics/StackTraceHelper.cs
System.Diagnostics.Tracing/EventAttribute.cs
System.Diagnostics.Tracing/EventCommand.cs
System.Diagnostics.Tracing/EventSource.cs
using System.Collections.Generic;
using Mono.Cecil;
using Mono.CompilerServices.SymbolWriter;
+using System.Runtime.InteropServices;
namespace Symbolicate
{
return true;
}
- static MethodInfo methodGetIL;
+ SeqPointInfo seqPointInfo;
private int GetILOffsetFromFile (int methodToken, uint methodIndex, int nativeOffset)
{
- if (string.IsNullOrEmpty (seqPointDataPath))
- return -1;
+ if (seqPointInfo == null)
+ seqPointInfo = SeqPointInfo.Read (seqPointDataPath);
- if (methodGetIL == null)
- methodGetIL = typeof (StackFrame).GetMethod ("GetILOffsetFromFile", BindingFlags.NonPublic | BindingFlags.Static);
-
- if (methodGetIL == null)
- throw new Exception ("System.Diagnostics.StackFrame.GetILOffsetFromFile could not be found, make sure you have an updated mono installed.");
-
- return (int) methodGetIL.Invoke (null, new object[] {seqPointDataPath, methodToken, methodIndex, nativeOffset});
+ return seqPointInfo.GetILOffset (methodToken, methodIndex, nativeOffset);
}
- static MethodInfo methodGetMethodFullName;
private string GetMethodFullName (MethodBase m)
{
-
- if (methodGetMethodFullName == null)
- methodGetMethodFullName = typeof (StackTrace).GetMethod ("GetFullNameForStackTrace", BindingFlags.NonPublic | BindingFlags.Static);
-
- if (methodGetMethodFullName == null)
- throw new Exception ("System.Exception.GetFullNameForStackTrace could not be found, make sure you have an updated mono installed.");
-
StringBuilder sb = new StringBuilder ();
- methodGetMethodFullName.Invoke (null, new object[] {sb, m});
+
+ StackTraceHelper.GetFullNameForStackTrace (sb, m);
return sb.ToString ();
}
if (!File.Exists (assemblyPath))
throw new ArgumentException ("assemblyPath does not exist: "+ assemblyPath);
- var assembly = Assembly.LoadFrom (assemblyPath);
+ var assembly = Assembly.ReflectionOnlyLoadFrom (assemblyPath);
MonoSymbolFile symbolFile = null;
var symbolPath = assemblyPath + ".mdb";
--- /dev/null
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+namespace Symbolicate
+{
+ static class BinaryReaderExtensions
+ {
+ public static int ReadVariableInt (this BinaryReader reader)
+ {
+ int val = 0;
+ for (var i = 0; i < 4; i++) {
+ var b = reader.ReadByte ();
+ val |= (b & 0x7f) << (7 * i);
+ if ((b & 0x80) == 0)
+ return val;
+ }
+
+ throw new Exception ("Invalid variable int");
+ }
+
+ public static int ReadVariableZigZagInt (this BinaryReader reader)
+ {
+ int enc = ReadVariableInt (reader);
+ int val = enc >> 1;
+ return ((enc & 1) == 0)? val : -val;
+ }
+ }
+
+ class SeqPointInfo
+ {
+ class MethodData
+ {
+ List<SeqPoint> seqPoints;
+
+ public static MethodData Read (BinaryReader reader)
+ {
+ var hasDebugData = reader.ReadVariableInt () != 0;
+ var dataSize = reader.ReadVariableInt ();
+ var dataEnd = reader.BaseStream.Position + dataSize;
+
+ var seqPoints = new List<SeqPoint> ();
+ SeqPoint prev = null;
+ while (reader.BaseStream.Position < dataEnd) {
+ var seqPoint = SeqPoint.Read (reader, prev, hasDebugData);
+ seqPoints.Add (seqPoint);
+ prev = seqPoint;
+ }
+
+ if (reader.BaseStream.Position != dataEnd)
+ throw new Exception ("Read more seq point than expected.");
+
+ return new MethodData () { seqPoints = seqPoints };
+ }
+
+ public bool TryGetILOffset (int nativeOffset, out int ilOffset)
+ {
+ ilOffset = 0;
+ SeqPoint prev = null;
+ foreach (var seqPoint in seqPoints) {
+ if (seqPoint.NativeOffset > nativeOffset)
+ break;
+ prev = seqPoint;
+ }
+
+ if (prev == null)
+ return false;
+
+ ilOffset = prev.ILOffset;
+ return true;
+ }
+ }
+
+ class SeqPoint
+ {
+ public readonly int ILOffset;
+ public readonly int NativeOffset;
+
+ public SeqPoint (int ilOffset, int nativeOffset)
+ {
+ ILOffset = ilOffset;
+ NativeOffset = nativeOffset;
+ }
+
+ public static SeqPoint Read (BinaryReader reader, SeqPoint prev, bool hasDebug)
+ {
+ var ilOffset = reader.ReadVariableZigZagInt ();
+ var nativeOffset = reader.ReadVariableZigZagInt ();
+
+ // Respect delta encoding
+ if (prev != null) {
+ ilOffset += prev.ILOffset;
+ nativeOffset += prev.NativeOffset;
+ }
+
+ //Read everything to ensure the buffer position is at the end of the seq point data.
+ if (hasDebug) {
+ reader.ReadVariableInt (); // flags
+
+ var next_length = reader.ReadVariableInt ();
+ for (var i = 0; i < next_length; ++i)
+ reader.ReadVariableInt ();
+ }
+
+ return new SeqPoint (ilOffset, nativeOffset);
+ }
+ };
+
+ Dictionary<Tuple<int,int>, MethodData> dataByIds;
+ Dictionary<int, MethodData> dataByTokens;
+
+ public static SeqPointInfo Read (string path)
+ {
+ using (var reader = new BinaryReader (File.Open (path, FileMode.Open)))
+ {
+ var dataByIds = new Dictionary<Tuple<int,int>, MethodData> ();
+ var dataByTokens = new Dictionary<int, MethodData> ();
+
+ var methodCount = reader.ReadVariableInt ();
+
+ for (var i = 0; i < methodCount; ++i) {
+ var methodToken = reader.ReadVariableInt ();
+ var methodIndex = reader.ReadVariableInt ();
+ var methodId = new Tuple<int, int> (methodToken, methodIndex);
+
+ var methodData = MethodData.Read (reader);
+
+ dataByIds.Add (methodId, methodData);
+ if (!dataByTokens.ContainsKey (methodToken))
+ dataByTokens.Add (methodToken, methodData);
+ }
+
+ return new SeqPointInfo { dataByIds = dataByIds, dataByTokens = dataByTokens };
+ }
+ }
+
+ public int GetILOffset (int methodToken, uint methodIndex, int nativeOffset)
+ {
+ MethodData methodData;
+ if (methodIndex == 0xffffff) {
+ if (!dataByTokens.TryGetValue (methodToken, out methodData))
+ throw new Exception (string.Format ("Could not find data for method token {0:X}", methodToken));
+ } else {
+ var methodId = new Tuple<int, int> (methodToken, (int)methodIndex);
+ if (!dataByIds.TryGetValue (methodId, out methodData))
+ throw new Exception (string.Format ("Could not find data for method token {0:X} with index {1:X}", methodToken, methodIndex));
+ }
+
+ int ilOffset;
+ if (!methodData.TryGetILOffset (nativeOffset, out ilOffset))
+ throw new Exception ("Could not retrieve IL offset");
+
+ return ilOffset;
+ }
+ }
+}
symbolicate.cs
-LocationProvider.cs
\ No newline at end of file
+LocationProvider.cs
+SeqPointInfo.cs
+../../class/corlib/System.Diagnostics/StackTraceHelper.cs
MonoMethod method;
MonoMethodPInvoke pinvoke;
} method;
- MonoMethodHeader *header;
MonoMethod *declaring; /* the generic method definition. */
MonoGenericContext context; /* The current instantiation */
MonoImageSet *owner; /* The image set that the inflated method belongs to. */
ICALL(PROCESS_13, "ShellExecuteEx_internal(System.Diagnostics.ProcessStartInfo,System.Diagnostics.Process/ProcInfo&)", ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal)
#endif /* !DISABLE_PROCESS_HANDLING */
-ICALL_TYPE(SFRAME, "System.Diagnostics.StackFrame", SFRAME_1)
-ICALL(SFRAME_1, "GetILOffsetFromFile", ves_icall_System_StackFrame_GetILOffsetFromFile)
-
ICALL_TYPE(STOPWATCH, "System.Diagnostics.Stopwatch", STOPWATCH_1)
ICALL(STOPWATCH_1, "GetTimestamp", mono_100ns_ticks)
return message;
}
-ICALL_EXPORT int
-ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, guint32 method_token, guint32 method_index, int native_offset)
-{
- guint32 il_offset;
- char *path_str = mono_string_to_utf8 (path);
-
- if (!mono_seq_point_data_get_il_offset (path_str, method_token, method_index, native_offset, &il_offset))
- il_offset = -1;
-
- g_free (path_str);
-
- return il_offset;
-}
-
ICALL_EXPORT gpointer
ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
{
static MonoMethodHeader*
inflate_generic_header (MonoMethodHeader *header, MonoGenericContext *context, MonoError *error)
{
- MonoMethodHeader *res;
- int i;
- res = (MonoMethodHeader *)g_malloc0 (MONO_SIZEOF_METHOD_HEADER + sizeof (gpointer) * header->num_locals);
+ size_t locals_size = sizeof (gpointer) * header->num_locals;
+ size_t clauses_size = header->num_clauses * sizeof (MonoExceptionClause);
+ size_t header_size = MONO_SIZEOF_METHOD_HEADER + locals_size + clauses_size;
+ MonoMethodHeader *res = (MonoMethodHeader *)g_malloc0 (header_size);
+ res->num_locals = header->num_locals;
+ res->clauses = (MonoExceptionClause *) &res->locals [res->num_locals] ;
+ memcpy (res->clauses, header->clauses, clauses_size);
+
res->code = header->code;
res->code_size = header->code_size;
res->max_stack = header->max_stack;
res->num_clauses = header->num_clauses;
res->init_locals = header->init_locals;
- res->num_locals = header->num_locals;
- res->clauses = header->clauses;
+
+ res->is_transient = TRUE;
mono_error_init (error);
- for (i = 0; i < header->num_locals; ++i) {
+ for (int i = 0; i < header->num_locals; ++i) {
res->locals [i] = mono_class_inflate_generic_type_checked (header->locals [i], context, error);
if (!is_ok (error))
goto fail;
}
if (res->num_clauses) {
- res->clauses = (MonoExceptionClause *)g_memdup (header->clauses, sizeof (MonoExceptionClause) * res->num_clauses);
- for (i = 0; i < header->num_clauses; ++i) {
+ for (int i = 0; i < header->num_clauses; ++i) {
MonoExceptionClause *clause = &res->clauses [i];
if (clause->flags != MONO_EXCEPTION_CLAUSE_NONE)
continue;
return NULL;
}
- mono_image_lock (img);
-
- if (imethod->header) {
- mono_metadata_free_mh (iheader);
- mono_image_unlock (img);
- return imethod->header;
- }
-
- mono_memory_barrier ();
- imethod->header = iheader;
-
- mono_image_unlock (img);
-
- return imethod->header;
+ return iheader;
}
if (method->wrapper_type != MONO_WRAPPER_NONE || method->sre_method) {
if (method->signature)
mono_metadata_free_inflated_signature (method->signature);
- if (!((method->flags & METHOD_ATTRIBUTE_ABSTRACT) || (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) || (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))) {
- MonoMethodHeader *header = imethod->header;
-
- if (header) {
- /* Allocated in inflate_generic_header () */
- for (i = 0; i < header->num_locals; ++i)
- mono_metadata_free_type (header->locals [i]);
- g_free (header->clauses);
- g_free (header);
- }
- }
-
g_free (method);
}
* Return the list of basic blocks of method. Return NULL on failure and set @error.
*/
MonoSimpleBasicBlock*
-mono_basic_block_split (MonoMethod *method, MonoError *error)
+mono_basic_block_split (MonoMethod *method, MonoError *error, MonoMethodHeader *header)
{
MonoError inner_error;
MonoSimpleBasicBlock *bb, *root;
const unsigned char *start, *end;
- MonoMethodHeader *header = mono_method_get_header_checked (method, &inner_error);
-
- mono_error_init (error);
-
- if (!header) {
- mono_error_set_not_verifiable (error, method, "Could not decode header due to %s", mono_error_get_message (&inner_error));
- mono_error_cleanup (&inner_error);
- return NULL;
- }
start = header->code;
end = start + header->code_size;
dump_bb_list (bb, &root, g_strdup_printf("AFTER LIVENESS %s", mono_method_full_name (method, TRUE)));
#endif
- mono_metadata_free_mh (header);
return bb;
fail:
- mono_metadata_free_mh (header);
mono_basic_block_free (bb);
return NULL;
}
};
MonoSimpleBasicBlock*
-mono_basic_block_split (MonoMethod *method, MonoError *error);
+mono_basic_block_split (MonoMethod *method, MonoError *error, MonoMethodHeader *header);
void
mono_basic_block_free (MonoSimpleBasicBlock *bb);
if (interrupted)
goto done;
- if (mono_coop_cond_timedwait (&threadpool->parked_threads_cond, &threadpool->active_threads_lock, rand_next ((void **)rand_handle, 5 * 1000, 60 * 1000)) != 0)
+ if (mono_coop_cond_timedwait (&threadpool->parked_threads_cond, &threadpool->active_threads_lock, rand_next (&rand_handle, 5 * 1000, 60 * 1000)) != 0)
timeout = TRUE;
mono_thread_info_uninstall_interrupt (&interrupted);
if (!ctx.valid)
goto cleanup;
- original_bb = bb = mono_basic_block_split (method, &error);
+ original_bb = bb = mono_basic_block_split (method, &error, ctx.header);
if (!mono_error_ok (&error)) {
ADD_VERIFY_ERROR (&ctx, g_strdup_printf ("Invalid branch target: %s", mono_error_get_message (&error)));
mono_error_cleanup (&error);
skip_dead_blocks = !dont_verify;
if (skip_dead_blocks) {
- original_bb = bb = mono_basic_block_split (method, &cfg->error);
+ original_bb = bb = mono_basic_block_split (method, &cfg->error, header);
CHECK_CFG_ERROR;
g_assert (bb);
}