I keep seeing these errors. I would love to know more about what is happening, but without the exception being marked as serializable, it won't show me what is happening. Any reason why these are not marked as serializable? This is on the 1.8.2 client.
System.Runtime.Serialization.SerializationException: Type 'Elasticsearch.Net.ElasticsearchServerException' in Assembly 'Elasticsearch.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d' is not marked as serializable.
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm)
at System.AppDomain.Serialize(Object o)
at System.AppDomain.MarshalObject(Object o)
You are absolutely right that these should be marked as serializable. I just pushed 1.8.3 which fixes this:
https://github.com/elastic/elasticsearch-net/releases/tag/1.8.3
Leaving this open because we need to do the same in 2.x and 5.x
Thank you!
Now I'm randomly getting this error. I can run my tests 100 times in a row on my dev machine and they never fail. But running them in AppVeyor is causing random failures.
System.Runtime.Serialization.SerializationException: Unable to find assembly 'Elasticsearch.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
at System.AppDomain.Deserialize(Byte[] blob)
at System.AppDomain.UnmarshalObject(Byte[] blob)
Thats unexpected, we don't do ilmerging or anything of the likes. Are you using NEST or Elasticsearch.NET?
Can you tell me a bit more in what context this is (re)thrown? Are you doing any remoting or using separate appdomains?
I'm using NEST and it's happening in an xunit test. My code doesn't do any appdomains or remoting, but xunit does.
Well I figured out that it was a problem with Xunit that was trying to load assemblies from the wrong appdomain where they didn't exist. That was hiding the real issue which was that I was saving documents on a timer while the tests were concurrently deleting the indexes and recreating them.
Glad you managed to figure it out, sad it took up such a big chunk of your time :cry:
Thanks for reporting back @ejsmith
After being halfway through adding this into 2.x branch i remembered .net core killed ISerializable.
I'm not going to forward port this to 2.x and master until new best practices emerge or this makes it into netstandard 2 and 2.x or master also bumps.
Most helpful comment
Well I figured out that it was a problem with Xunit that was trying to load assemblies from the wrong appdomain where they didn't exist. That was hiding the real issue which was that I was saving documents on a timer while the tests were concurrently deleting the indexes and recreating them.