vlingo-net / xoom-net-actors

Type safe Actor Model toolkit for reactive concurrency and resiliency using C# and other .NET languages.
Mozilla Public License 2.0
39 stars 18 forks source link

Dynamic proxy generated class doesn't compile #36

Closed tjaskula closed 5 years ago

tjaskula commented 5 years ago

I have this following error rising in vlingo-net-wire

System.ArgumentException: Actor proxy IResponseSenderChannel`1 not created for main or test: Actor proxy IResponseSenderChannel`1 not created because: Dynamically generated class source did not compile: Vlingo.Wire.Channel.ResponseSenderChannel__Proxy ---> System.ArgumentException: Actor proxy IResponseSenderChannel`1 not created because: Dynamically generated class source did not compile: Vlingo.Wire.Channel.ResponseSenderChannel__Proxy ---> System.ArgumentException: Dynamically generated class source did not compile: Vlingo.Wire.Channel.ResponseSenderChannel__Proxy
  at at Vlingo.Common.Compiler.DynaCompiler.Compile(Input input)
  at at Vlingo.Actors.ActorProxy.TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, ProxyGenerator generator, String targetClassName)
  --- End of inner exception stack trace ---
  at at Vlingo.Actors.ActorProxy.TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, ProxyGenerator generator, String targetClassName)
  at at Vlingo.Actors.ActorProxy.TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, String targetClassName)
  --- End of inner exception stack trace ---
  at at Vlingo.Actors.ActorProxy.TryGenerateCreate(Type protocol, Actor actor, IMailbox mailbox, String targetClassName)
  at at Vlingo.Actors.ActorProxy.CreateFor(Type protocol, Actor actor, IMailbox mailbox)
  at at Vlingo.Actors.ActorProxy.CreateFor[T](Actor actor, IMailbox mailbox)
  at at Vlingo.Actors.Stage.ActorProxyFor[T](Actor actor, IMailbox mailbox)
  at at Vlingo.Actors.Actor.SelfAs[T]()
  at Vlingo.Wire.Channel.SocketChannelSelectionProcessorActor..ctor(IRequestChannelConsumerProvider provider, String name, Int32 maxBufferPoolSize, Int32 messageBufferSize, Int64 probeInterval) in /Users/tjaskula/Documents/GitHub/vlingo-net-wire/src/Vlingo.Wire/Channel/SocketChannelSelectionProcessorActor.cs:46

has to be investigated.

tjaskula commented 5 years ago

Would be nice to report code that doesn't compile.

tjaskula commented 5 years ago

Ok, this is source that was generated:

using System;
using System.Collections.Generic;
using Vlingo.Actors;
using Vlingo.Common;
using Vlingo.Wire.Channel;
using System.Net.Sockets;

namespace Vlingo.Wire.Channel
{
    public class ResponseSenderChannel__Proxy : IResponseSenderChannel<Socket>
    {
        private const string AbandonRepresentation1 = "Abandon(RequestResponseContext<Socket>)";
        private const string RespondWithRepresentation2 = "RespondWith(RequestResponseContext<Socket>, IConsumerByteBuffer)";

        private readonly Actor actor;
        private readonly IMailbox mailbox;

        public ResponseSenderChannel__Proxy(Actor actor, IMailbox mailbox)
        {
            this.actor = actor;
            this.mailbox = mailbox;
        }

        public void Abandon(RequestResponseContext<Socket> context)
        {
            if(!actor.IsStopped)
            {
                Action<IResponseSenderChannel<Socket>> consumer = x => x.Abandon(context);
                if(mailbox.IsPreallocated)
                {
                    mailbox.Send(actor, consumer, null, AbandonRepresentation1);
                }
                else
                {
                    mailbox.Send(new LocalMessage<IResponseSenderChannel<Socket>>(actor, consumer, AbandonRepresentation1));
                }
            }
            else
            {
                actor.DeadLetters.FailedDelivery(new DeadLetter(actor, AbandonRepresentation1));
            }
        }
        public void RespondWith(RequestResponseContext<Socket> context, IConsumerByteBuffer buffer)
        {
            if(!actor.IsStopped)
            {
                Action<IResponseSenderChannel<Socket>> consumer = x => x.RespondWith(context, buffer);
                if(mailbox.IsPreallocated)
                {
                    mailbox.Send(actor, consumer, null, RespondWithRepresentation2);
                }
                else
                {
                    mailbox.Send(new LocalMessage<IResponseSenderChannel<Socket>>(actor, consumer, RespondWithRepresentation2));
                }
            }
            else
            {
                actor.DeadLetters.FailedDelivery(new DeadLetter(actor, RespondWithRepresentation2));
            }
        }

    }
}

It doesn't compile because it lacks an using for IConsumerByteBuffer. Adding the using produces valid code.

tjaskula commented 5 years ago

Another one on

using System;
using System.Collections.Generic;
using Vlingo.Actors;
using Vlingo.Common;
namespace Vlingo.Common
{
public class Scheduled__Proxy : IScheduled
{
  private const string IntervalSignalRepresentation1 = "IntervalSignal(IScheduled, object)";

  private readonly Actor actor;
  private readonly IMailbox mailbox;

  public Scheduled__Proxy(Actor actor, IMailbox mailbox)
  {
    this.actor = actor;
    this.mailbox = mailbox;
  }

  public void IntervalSignal(IScheduled scheduled, object data)
  {
    if(!actor.IsStopped)
    {
      Action<IScheduled> consumer = x => x.IntervalSignal(scheduled, data);
      if(mailbox.IsPreallocated)
      {
        mailbox.Send(actor, consumer, null, IntervalSignalRepresentation1);
      }
      else
      {
        mailbox.Send(new LocalMessage<IScheduled>(actor, consumer, IntervalSignalRepresentation1));
      }
    }
    else
    {
      actor.DeadLetters.FailedDelivery(new DeadLetter(actor, IntervalSignalRepresentation1));
    }
  }

}
}

vlingo-net/actors: Generating proxy for main: IScheduled Dynamically generated class source for Vlingo.Common.Scheduled__Proxy did not compile because: The type or namespace name 'Actors' does not exist in the namespace 'Vlingo' (are you missing an assembly reference?) at Vlingo.Common.Compiler.DynaCompiler.Compile(Input input)

tjaskula commented 5 years ago

This one with IScheduled doesn't seem it lacks any using. It's just that it cannot resolve a reference to Vlingo.Actors somehow. I've added the reference to the UT project but this doesn't seem to fix the problem.

The one with ResponseSenderChannel__Proxy I fixed by adding the generated file to the project Vlingo.Wire but doesn't seem I can do the same with Scheduled__Proxy

tjaskula commented 5 years ago

Fixed by #38