serilog-contrib / serilog-sinks-elasticsearch

A Serilog sink that writes events to Elasticsearch
Apache License 2.0
434 stars 196 forks source link

ElasticSearch.Net is throwing exception on Xamarin.iOS related to dynamic content #115

Closed Qwin closed 6 years ago

Qwin commented 7 years ago

UPDATE: So after some testing and replacing the whole elasticsearch serializer with a custom one, I figured out the problem is indeed the dynamic dictionary (DynamicResponse) which uses dynamic type. This is not allowed by Xamarin.iOS. I am not sure what we could do to resolve this issue. Maybe provide a different implementation and allow users to have a boolean in settings "UseDynamicTypes" to choose if they want to use the dynamicresponse. I posted this issue at ElasticSearch.Net github as well.

Hi Everyone,

So my issue is that after using the latest elasticsearch sink plugin I am getting the following error:

2017-06-30T19:58:49.0697530Z Exception while emitting periodic batch from Serilog.Sinks.Elasticsearch.ElasticsearchLogShipper: Elasticsearch.Net.UnexpectedElasticsearchClientException: Operation is not supported on this platform. ---> System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Runtime.InteropServices.Marshal.IsComObject (System.Object o) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs:744 at Microsoft.CSharp.RuntimeBinder.BinderHelper.IsComObject (System.Object obj) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs:162 at Microsoft.CSharp.RuntimeBinder.BinderHelper.IsDynamicallyTypedRuntimeProxy (System.Dynamic.DynamicMetaObject argument, Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo info) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs:214 at Microsoft.CSharp.RuntimeBinder.BinderHelper.DeduceArgumentRestriction (System.Int32 parameterIndex, Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder callPayload, System.Dynamic.DynamicMetaObject argument, Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo info) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs:253 at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind (System.Dynamic.DynamicMetaObjectBinder action, Microsoft.CSharp.RuntimeBinder.RuntimeBinder binder, System.Dynamic.DynamicMetaObject[] args, System.Collections.Generic.IEnumerable1[T] arginfos, System.Dynamic.DynamicMetaObject onBindingError) [0x000a3] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs:64 at Microsoft.CSharp.RuntimeBinder.CSharpInvokeConstructorBinder.Bind (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs:41 at System.Dynamic.DynamicMetaObjectBinder.Bind (System.Object[] args, System.Collections.ObjectModel.ReadOnlyCollection1[T] parameters, System.Linq.Expressions.LabelTarget returnLabel) [0x000c6] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Dynamic/DynamicMetaObjectBinder.cs:90 at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T] (System.Runtime.CompilerServices.CallSite1[T] site, System.Object[] args) [0x00019] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSiteBinder.cs:129 at System.Runtime.CompilerServices.CallSiteOps.Bind[T] (System.Runtime.CompilerServices.CallSiteBinder binder, System.Runtime.CompilerServices.CallSite1[T] site, System.Object[] args) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSiteOps.cs:157 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow (System.Reflection.TargetInvocationException exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs:174 at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) [0x00035] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs:333 at System.Linq.Expressions.Interpreter.Interpreter.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) [0x00015] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Interpreter.cs:63 at System.Linq.Expressions.Interpreter.LightLambda.Run3[T0,T1,T2,TRet] (T0 arg0, T1 arg1, T2 arg2) [0x00038] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.12/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightLambda.Generated.cs:107 at Elasticsearch.Net.DynamicResponse.set_Item (System.String name, System.Object value) [0x0004e] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.DynamicResponse.Create (System.Collections.Generic.IDictionary2[TKey,TValue] values) [0x00024] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ElasticsearchNetJsonStrategy.DeserializeObject (System.Object value, System.Type type) [0x00027] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.SimpleJson.DeserializeObject (System.String json, System.Type type, Elasticsearch.Net.IJsonSerializerStrategy jsonSerializerStrategy) [0x00025] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.SimpleJson.DeserializeObject[T] (System.String json, Elasticsearch.Net.IJsonSerializerStrategy jsonSerializerStrategy) [0x00000] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ElasticsearchDefaultSerializer.Deserialize[T] (System.IO.Stream stream) [0x0003b] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ResponseBuilder1[TReturn].SetBody (Elasticsearch.Net.ElasticsearchResponse1[T] response, System.IO.Stream stream) [0x000b6] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ResponseBuilder1[TReturn].ToResponse () [0x00023] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.HttpConnection.Request[TReturn] (Elasticsearch.Net.RequestData requestData) [0x000b0] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TReturn] (Elasticsearch.Net.RequestData requestData) [0x0008b] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.Transport1[TConnectionSettings].Request[TReturn] (Elasticsearch.Net.HttpMethod method, System.String path, Elasticsearch.Net.PostData1[T] data, Elasticsearch.Net.IRequestParameters requestParameters) [0x000b6] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 --- End of inner exception stack trace --- at Elasticsearch.Net.Transport1[TConnectionSettings].Request[TReturn] (Elasticsearch.Net.HttpMethod method, System.String path, Elasticsearch.Net.PostData1[T] data, Elasticsearch.Net.IRequestParameters requestParameters) [0x00140] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[T] (Elasticsearch.Net.HttpMethod method, System.String path, Elasticsearch.Net.PostData1[T] data, Elasticsearch.Net.IRequestParameters requestParameters) [0x00006] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Elasticsearch.Net.ElasticLowLevelClient.Bulk[T] (Elasticsearch.Net.PostData1[T] body, System.Func`2[T,TResult] requestParameters) [0x00022] in <8bed9f0210e247bc8e6c4ff69cda5ce0>:0 at Serilog.Sinks.Elasticsearch.ElasticsearchLogShipper.OnTick () [0x00161] in :0

` After doing some research I found out that ElasticSearch.Net is using internally some dynamic code generation that is causing this error. I am using LogShipper and the bulk api.

ElasticSearch.Net 5.4.0 ElasticSearch.Sink 5.3.0 Serilog 2.5.0

Mono: 5.2.0.196 Using Beta version of Xamarin.iOS: 10.12.0.12

So I am not sure who is at fault. I do know Xamarin.iOS doesn't support dynamic code generation. (see Xamarin.iOS limitation docs).

Qwin commented 7 years ago

This bug has been fixed with newer version of Xamarin.iOS 10.12.0.14. This issue can be closed.

graemechristie commented 7 years ago

@Qwin Really ? https://bugzilla.xamarin.com/show_bug.cgi?id=57919 says it is not fixed until 10.14.0.5 which will not be alpha for some time.

Qwin commented 7 years ago

@graemechristie correct I thought it was fixed but it wasn't but u can see from the bug report you have linked I am the one that actually created that bug :)

Qwin commented 7 years ago

My real name is Robertalmalak ;)

mivano commented 6 years ago

Assuming it is fixed for now and not directly a sink issue I m closing this issue. Feel free to reopen if we need to have a further look.