我已经用C#编写了一个Ignite .Net服务,该服务在Linux / NET Core 2.2上运行。现在,我试图在.Net Framework Web应用程序中使用它。
Ignition.ClientMode = true;
var igniteCfg = new IgniteConfiguration()
{
IgniteHome = System.Web.HttpContext.Current.Server.MapPath(@"~\bin\")
};
using (var ignite = Ignition.Start(igniteCfg))
{
var services = ignite.GetServices();
IQuoteGeneratorContract proxy = services.GetServiceProxy<IQuoteGeneratorContract>("QuoteService");
quotes = proxy.GenerateQuotes(quoteRequestMapped);
}
但是,我在调用Ignition.Start时遇到了一个奇怪的异常:
Type 'Domain.ElasticCachedReference`1[[Domain.Partner, Utility.Click.Domain, Version=3.10.56.40, Culture=neutral, PublicKeyToken=null]]' in Assembly 'Utility.Click.Domain, Version=3.10.56.40, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
堆栈跟踪:
Server stack trace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
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.SerializeMessageParts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodCallMessage mcm)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossible(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System._AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
at Apache.Ignite.Core.Impl.Unmanaged.Jni.Jvm.GetCallbacksFromDefaultDomain()
at Apache.Ignite.Core.Impl.Unmanaged.Jni.Jvm..ctor(IntPtr jvmPtr)
at Apache.Ignite.Core.Impl.Unmanaged.Jni.Jvm.GetOrCreate(IList`1 options)
at Apache.Ignite.Core.Impl.IgniteManager.CreateJvmContext(IgniteConfiguration cfg, ILogger log)
at Apache.Ignite.Core.Ignition.Start(IgniteConfiguration cfg)
at Domain.ServiceAdapters.QuoteServiceAdapter.GenerateQuotes(IEnumerable`1 products, Tender tender, Dictionary`2 customCPs) in C:\Users\alexavrutin\Projects\utilityclick\src\Domain\-Logic\ServiceAdapters\QuoteServiceAdapter.cs:line 54
at Domain.Tender.Submit(Object shardingKey, TenderOptions tenderOptions, Boolean isSkipRecalcManualQuotes, Dictionary`2 customCPs, Boolean forceGenerateSMEQuotes) in C:\Users\alexavrutin\Projects\utilityclick\src\Domain\-Logic\Tender.cs:line 616
我必须说异常消息是绝对正确的:Domain.ElasticCachedReference类型实际上未标记为[Serializable]。但是,我没有在任何Ignite服务中使用这种类型,也没有将其存储在Ignite缓存中。我只是想在定义和使用此类的同一应用程序中运行Ignite,毕竟,我只是启动Ignite而不是调用任何服务或运行分布式闭包。
我已经查看了Ignite源代码,并怀疑该异常是在Net Framework方法中引发的,并且可能与Activator实例化类型的方式有关,而不是与Ignite本身有关。但是,我想知道如何防止这种异常的发生?谢谢!
我正在运行客户端的计算机上使用以下软件: Windows 10专业版, Visual Studio 2017, C#7.1, 带有ASP.NET的Net Framework 4.7.1, Apache Ignite .Net 2.7