orleans icon indicating copy to clipboard operation
orleans copied to clipboard

RegexImplicitStreamSubscription not working

Open cjenp opened this issue 7 years ago • 12 comments

Implicit stream subscription with RegexImplicitStreamSubscription attribute is not working:

System.Runtime.Serialization.SerializationException: 'Type 'System.Text.RegularExpressions.RegexReplacement' in Assembly 'System.Text.RegularExpressions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.'

cjenp avatar Dec 12 '18 12:12 cjenp

which version of orleans is this?

xiazen avatar Dec 14 '18 19:12 xiazen

can you provide more information on this exception? such as its stack trace?

xiazen avatar Dec 14 '18 19:12 xiazen

The exception occurs when the client trys to connect to the cluster.

System.Runtime.Serialization.SerializationException HResult=0x8013150C Message=Type 'System.Text.RegularExpressions.RegexReplacement' in Assembly 'System.Text.RegularExpressions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable. Source=System.Private.CoreLib StackTrace: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Orleans.OrleansTaskExtentions.<g__ConvertAsync|4_0>d1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Orleans.OutsideRuntimeClient.<StreamingInitialize>d__54.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Orleans.OutsideRuntimeClient.<<StartInternal>g__ExecuteWithRetries|56_3>d.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Orleans.OutsideRuntimeClient.<<StartInternal>g__ExecuteWithRetries|56_3>d.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Orleans.OutsideRuntimeClient.<StartInternal>d__56.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Orleans.OutsideRuntimeClient.<Start>d__55.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Orleans.ClusterClient.<Connect>d__19.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at WebApiO.Startup.<StartClientWithRetries>d__8.MoveNext() in C:\GitRoot\SmartCacheOrleankka\SmartCacheOrleans\WebApiO\Startup.cs:line 89 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at WebApiO.Startup.ConfigureServices(IServiceCollection services) in C:\GitRoot\SmartCacheOrleankka\SmartCacheOrleans\WebApiO\Startup.cs:line 35

cjenp avatar Dec 17 '18 07:12 cjenp

At first look, it seems the issue here is in serialization of ImplicitStreamSubscriberTable.predicates, which is a list containing IStreamNamespacePredicate.

So currently the client needs to be able to deserialize all IStreamNamespacePredicate implementations in the system. This includes RegexStreamNamespacePredicate and @alexeyzimarev's custom predicate.

For the RegEx predicate, we can serialize the Regex pattern as a string using custom serialization methods.

For the remainder (including @alexeyzimarev's issue #5274), we will have to make sure that all clients have access to all predicate types for now.

In the long run, we could consider alternative solutions, such as shifting the responsibility for predicate matching, etc, to the gateway/silo (eg, the simplest solution would be to have a grain perform the matching task and pass the results to the client).

ReubenBond avatar Dec 19 '18 16:12 ReubenBond

@ReubenBond I have tried adding the predicate type to the client project and also added the assembly as an application part to the client initialisation code, but it didn't help.

alexeyzimarev avatar Dec 19 '18 19:12 alexeyzimarev

@alexeyzimarev could you please also add [Serializable] on the predicate type? If that does not work, please upload your obj\<Configuration>\<TargetFramework>\<ProjectName>.orleans.g.cs file(s) eg to gist.github.com, and add a link to your original issue and we can debug it.

ReubenBond avatar Dec 19 '18 19:12 ReubenBond

@ReubenBond as the matter of fact I did it from the start and apparently, it didn't help.

    public class StartsWithImplicitStreamSubscriptionAttribute : ImplicitStreamSubscriptionAttribute
    {
        public StartsWithImplicitStreamSubscriptionAttribute(string startsWith)
            : base(new StartsWithStreamNamespacePredicate(startsWith)){}
    }

    [Serializable]
    public class StartsWithStreamNamespacePredicate : IStreamNamespacePredicate
    {
        private readonly string _startsWith;

        public StartsWithStreamNamespacePredicate(string startsWith) => _startsWith = startsWith;

        public bool IsMatch(string streamNameSpace) => streamNameSpace.StartsWith(_startsWith);
    }

alexeyzimarev avatar Dec 19 '18 19:12 alexeyzimarev

@alexeyzimarev could you upload the orleans.g.cs file? Does the client have the code generation package installed?

ReubenBond avatar Dec 19 '18 19:12 ReubenBond

@ReubenBond I confirm that it started to work when I placed the custom attribute to the grains interface project, which has the MSBuild code generation package referenced.

alexeyzimarev avatar Dec 19 '18 19:12 alexeyzimarev

Ok great, thank you.

ReubenBond avatar Dec 19 '18 19:12 ReubenBond

@alexeyzimarev can we close this ? thanks @ReubenBond for taking a look on this.

xiazen avatar Jan 02 '19 23:01 xiazen

close this since it looks to me the problem is solved. feel free to reopen.

xiazen avatar Feb 27 '19 22:02 xiazen