locked
cannot assign data from an "internal" variable in an outer scope variable RRS feed

  • Question

  • Hello everybody,

    The following activity generates the design time error below:

     

    new Assign  {

        To = new OutArgument<Req>(this.RequestData),

        Value = new InArgument<Req>(requestData)

    },

     

    Where requestData is a private Variable, internal to my Operation activity and this.RequestData is a public variable of it.

     

    Error      43          

    The private implementation of activity '856: OperationActivityInterop<RichiestaListaDipendenzePerBanca,RispostaListaDipendenzePerBanca>' has the following validation error:  

    The referenced Variable object (Name = 'RequestData') is not visible at this scope

    There may be another location reference with the same name that is visible at this scope, but it does not reference the same location.

                    D:\Creval.ABC\Mainline\Servizi\ServiziComuni\Creval.ABC.Servizi.ServiziComuni.Struttura.Tasks\StrutturaService.xamlx                0             0            

     

     

    Also, a quite similar statement

    new Assign  {

        To = new OutArgument<Req>(ctx => this.Request.Get(ctx)),

        Value = new InArgument<Req>(requestData)

    },

     

    Seems to work fine when assigning the same private Variable to the this.Request public Argument of the operation.

     

    So, I wish to understand:

    1.  Why is this.RequestData (the public activity variable) not visible at the inner scope of the Assign statement?

    2.  Why is, public the argument this.Request visible to the same Assign statement?

     

     

    I tried then to bind this.Request argument my Imported child interop activity with the following code:

     

    InArgument<Req> requestIn = new LambdaValue<Req>(ctx => this.Request.Get(ctx));

    this.Body.ActivityProperties["Request"] = requestIn;

     

    but I get the following error

     

    Error  44    

    The private implementation of activity '857: Interop' has the following validation error in the activity '861: LambdaValue<RichiestaListaDipendenzePerBanca>':  

    An error occurred while attempting to extract the target object of type 'System.Activities.InOutArgument`1[Creval.ABC.Messaggi.ServiziComuni.Struttura.RichiestaListaDipendenzePerBanca]' from the method call expression '856: OperationActivityInterop<RichiestaListaDipendenzePerBanca,RispostaListaDipendenzePerBanca>.Request.Get(ctx)'.  Note that the expression determining the object of type 'System.Activities.InOutArgument`1[Creval.ABC.Messaggi.ServiziComuni.Struttura.RichiestaListaDipendenzePerBanca]' must not require the runtime context.  Error: The sub-expression for the object of type 'System.Activities.InOutArgument`1[Creval.ABC.Messaggi.ServiziComuni.Struttura.RichiestaListaDipendenzePerBanca]' resulted in a null value.

           D:\Creval.ABC\Mainline\Servizi\ServiziComuni\Creval.ABC.Servizi.ServiziComuni.Struttura.Tasks\StrutturaService.xamlx       0      0            

     

    So, here, I wish to understand:

    ·         What does the error really mean?

    ·         is there a way to bind the Imported child Body activity directly to the Operation Request parameter (without having to assign the parameter value to a variable)?

     

    Thank you very much for your help.

    Dario

     

    PS. I attach the activity code, for better clarity.

    Should you need any information please, let me know.

     

     

        #region OperationActivityInterop

        [ContentProperty("Body")]

        public class OperationActivityInterop<Req, Res> : Activity

            where Req : RichiestaBase, new()

            where Res : RispostaBase, new()

        {

            #region .ctor

            public OperationActivityInterop() {

                this.RequestData = new Variable<Req> { Name = "RequestData" };

                this.ResponseData = new Variable<Res> { Name = "ResponseData" };

            }

            #endregion

     

            #region Implementation

            protected override Func<Activity> Implementation

            {

                get

                {

                    DelegateInArgument<Exception> ex = new DelegateInArgument<Exception>();

                   

                    Func<Activity> implementation = () =>

                    {

                        Variable<Req> requestData = new Variable<Req> { Name = "RequestDataInternal" }; // internal variable used for the Receive and SendReply

                        Variable<Res> responseData = new Variable<Res> { Name = "ResponseDataInternal" };

     

                        IDictionary<string, Argument> bodyProps = this.Body != null ? this.Body.ActivityProperties : null;

                        if (bodyProps != null)

                        {

                            InArgument<Req> requestIn = new LambdaValue<Req>(ctx => this.Request.Get(ctx)); // this gives Error 44!!!!!

                            //InArgument requestIn = new InArgument<Req>(this.RequestData); // ok (design time) but requires the assignment that gives Error 43!!!!

                            this.Body.ActivityProperties["Request"] = requestIn;

     

                            OutArgument<Req> requestOut = new LambdaReference<Req>(ctx => this.Request.Get(ctx)); // this gives Error 44 !!!!!

                            //OutArgument requestOut = new OutArgument<Req>(this.RequestData); // ok (design time) but requires the assignment that gives Error 43!!!!

                            this.Body.ActivityProperties["RequestOut"] = requestOut;

     

                            InArgument<Res> responseIn = new LambdaValue<Res>(ctx => this.Response.Get(ctx)); // this gives Error 44!!!!!

                            // InArgument responseIn = new InArgument<Res>(this.ResponseData); // ok (design time) but requires the assignment that gives Error 43!!!!

                            this.Body.ActivityProperties["Response"] = responseIn;

     

                            OutArgument<Res> responseOut = new LambdaReference<Res>(ctx => this.Response.Get(ctx)); // this gives Error 44       !!!!!

                            // OutArgument responseOut = new OutArgument<Res>(this.ResponseData); // ok (design time) but requires the assignment that gives Error 43!!!!

                            this.Body.ActivityProperties["ResponseOut"] = responseOut;

                        }

     

                        Receive receive = new Receive()

                        {

                            DisplayName = "ReceiveRequest",

                            CanCreateInstance = true,

                            Action = this.Action,

                            OperationName = this.OperationName,

                            ServiceContractName = this.ServiceContractName,

                            Content = ReceiveContent.Create(new OutArgument<Req>(requestData))

                        };

                        Sequence imp = new Sequence()

                        {

                            Variables = { requestData, responseData },

                            Activities = {

                                receive,

                                new Assign  {

                                    To = new OutArgument<Req>(ctx => this.Request.Get(ctx)),

                                    Value = new InArgument<Req>(requestData)

                                },

                                //new Assign  { // this gives Error 43 !!!!!

                                //    To = new OutArgument<Req>(this.RequestData),

                                //    Value = new InArgument<Req>(requestData)

                                //},

                                new TryCatch() {

                                    DisplayName = "TryCatch",

                                    Try = this.Body,

                                    Finally = new Sequence() {

                                        Activities = {

                                            new Assign  {

                                                To = new OutArgument<Res>(ctx => this.Response.Get(ctx)),

                                                Value = new InArgument<Res>(responseData)

                                            },

                                            new SendReply() {

                                                Request = receive,

                                                Content = new SendMessageContent() {

                                                    DeclaredMessageType = typeof(Res),

                                                    Message = new InArgument<Res>(ctx => this.Response.Get(ctx))

                                                }

                                            }

                                        }

                                    }

                                }

                            }

                        };

     

                        return imp;

                    };

     

                    return implementation;

                }

                set { }

            }

            #endregion

     

            #region CacheMetadata

            protected override void CacheMetadata(ActivityMetadata metadata)

            {

                //base.CacheMetadata(metadata);

                if (this.Body != null)

                {

                    RuntimeArgument reqArgument = new RuntimeArgument("Request", typeof(Req), ArgumentDirection.InOut, false);

                    metadata.Bind(this.Request, reqArgument);

                    metadata.AddArgument(reqArgument);

     

                    RuntimeArgument resArgument = new RuntimeArgument("Response", typeof(Res), ArgumentDirection.InOut, false);

                    metadata.Bind(this.Response, resArgument);

                    metadata.AddArgument(resArgument);

     

                    metadata.AddVariable(this.RequestData);

                    metadata.AddVariable(this.ResponseData);

     

                    metadata.AddImportedChild(this.Body);

                }

            }

            #endregion

     

            #region Request

            public InOutArgument<Req> Request { get; set; }

            #endregion

            #region Response

            public InOutArgument<Res> Response { get; set; }

            #endregion

            #region RequestData // public variable (at Operation activity scope)

            public Variable<Req> RequestData { get; set; }

            #endregion

            #region ResponseData // public variable (at Operation activity scope)

            public Variable<Res> ResponseData { get; set; }

            #endregion

     

            #region Body // Interop activity (it must be bound to Request and Response data)

            public Interop Body { get; set; }

            #endregion

     

            #region Action

            [DefaultValue((string)null)]

            public string Action { get; set; }

            #endregion

            #region OperationName

            [DefaultValue((string)null)]

            public string OperationName { get; set; }

            #endregion

            #region ServiceContractName

            [TypeConverter(typeof(ServiceXNameTypeConverter)), DefaultValue((string)null)]

            public XName ServiceContractName { get; set; }

            #endregion

        }

        #endregion

     

     


    darioa
    Wednesday, January 12, 2011 9:51 PM

Answers