If you use a sharded cluster in .NET Core 3.0 the code will crash with a TypeInitializationException. This is due to issue #118 in Hyperion.
You can reproduce this by grabbing the Petabridge.App.Web project and adding two lines to create a shard configuration.
Adding in AkkaService.cs:
var clusterSharding = ClusterSharding.Get(Sys);
var shardRegion = clusterSharding.Start("test", Props.Empty,
ClusterShardingSettings.Create(Sys), new MessageExtractor());
Leads to this exception:
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'Hyperion.SerializerOptions' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Hyperion.SerializerFactories.ExceptionSerializerFactory' threw an exception.
---> System.ArgumentNullException: Value cannot be null. (Parameter 'type')
at System.Reflection.TypeExtensions.GetMethod(Type type, String name, BindingFlags bindingAttr)
at Hyperion.SerializerFactories.ExceptionSerializerFactory..cctor()
--- End of inner exception stack trace ---
at Hyperion.SerializerFactories.ExceptionSerializerFactory..ctor()
at Hyperion.SerializerOptions..cctor()
--- End of inner exception stack trace ---
at Hyperion.SerializerOptions..ctor(Boolean versionTolerance, Boolean preserveObjectReferences, IEnumerable`1 surrogates, IEnumerable`1 serializerFactories, IEnumerable`1 knownTypes, Boolean ignoreISerializable)
at Akka.DistributedData.Serialization.ReplicatorMessageSerializer..ctor(ExtendedActorSystem system)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Akka.Serialization.Serialization..ctor(ExtendedActorSystem system)
at Akka.Actor.Internal.ActorSystemImpl.ConfigureSerialization()
at Akka.Actor.Internal.ActorSystemImpl.Akka.Actor.Internal.ISupportSerializationConfigReload.ReloadSerialization()
at Akka.Actor.Settings.RebuildConfig()
at Akka.Actor.Settings.InjectTopLevelFallback(Config config)
at Akka.Cluster.Sharding.ClusterSharding..ctor(ExtendedActorSystem system)
at Akka.Cluster.Sharding.ClusterShardingExtensionProvider.CreateExtension(ExtendedActorSystem system)
at Akka.Actor.ExtensionIdProvider`1.Akka.Actor.IExtensionId.CreateExtension(ExtendedActorSystem system)
at Akka.Actor.Internal.ActorSystemImpl.<>c__DisplayClass56_0.<RegisterExtension>b__1()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Akka.Actor.Internal.ActorSystemImpl.TryGetExtension(Type extensionType, Object& extension)
at Akka.Actor.Internal.ActorSystemImpl.GetExtension(IExtensionId extensionId)
at Akka.Actor.ExtensionIdProvider`1.Get(ActorSystem system)
at Akka.Actor.ExtensionIdProvider`1.Akka.Actor.IExtensionId.Get(ActorSystem system)
at Akka.Actor.Internal.ActorSystemImpl.RegisterExtension(IExtensionId extension)
at Akka.Actor.ActorSystemWithExtensions.WithExtension[T,TI](ActorSystem system)
at Akka.Cluster.Sharding.ClusterSharding.Get(ActorSystem system)
at Petabridge.App.Web.AkkaService.StartAsync(CancellationToken cancellationToken) in /Users/bromanko/Code/oss/Petabridge.App.Web/src/Petabridge.App.Web/AkkaService.cs:line 45
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Petabridge.App.Web.Program.Main(String[] args) in /Users/bromanko/Code/oss/Petabridge.App.Web/src/Petabridge.App.Web/Program.cs:line 18
_Originally posted by @bromanko in https://github.com/akkadotnet/akka.net/issues/3943#issuecomment-538543967_
Need to do a new release of Hyperion.
Hyperion v0.9.9 is now live on NuGet: https://github.com/akkadotnet/Hyperion/releases/tag/0.9.9
We need to update our local dependencies in Akka.NET and release a new beta / nightly to help users get up and running on .NET Core 3.0.
Yeah, it's not indexed yet but will be soon: https://www.nuget.org/packages/Hyperion/0.9.9
https://github.com/akkadotnet/akka.net/pull/3960 - bumping off a nightly build now. You can install them from here: https://getakka.net/community/getting-access-to-nightly-builds.html
Give that a try and let me know if this does or doesn't resolve the issue!
Sweet! I can confirm that this works in the Petabridge.App.Web sample project.
@bromanko thanks Brian. We'll do a v1.4.0-beta3 release so people can get this fix without having to rely on the nightly feed.