Dynamic object arguments in WF4 Activity - workflow-foundation-4

Is it possible to use dynamic objects (extending DynamicObject) in WF4 Activity that can be used in expressions?
I get the following error messages when running a unit test that invokes an activity that had a dynamic object as a parameter.
using DynamicObject as the argument type
System.Activities.InvalidWorkflowException : The following errors were
encountered while processing the workflow tree:
'Literal': Literal only supports value types and the
immutable type System.String. The type System.Dynamic.DynamicObject
cannot be used as a literal. 'Legal': The private implementation of
activity '1: Legal' has the following validation error: Compiler
error(s) encountered processing expression "deal.Region = "EMEA"".
'Region' is not a member of 'System.Dynamic.DynamicObject'.
Using actual type as argument type
System.Activities.InvalidWorkflowException : The following errors were
encountered while processing the workflow tree:
'Literal': Literal only supports value types and the
immutable type System.String. The type
WorkflowTest.DealValueHelper cannot be used as a literal.
'Legal': The private implementation of activity '1: Legal' has the
following validation error: Compiler error(s) encountered processing
expression "deal.Region = "EMEA"". 'Region' is not a member of
'WorkflowTest.DealValueHelper'.

Yes, this absolutely works. I've created just such an object in Microsoft.Activities.Extensions.WorkflowArguments.
What you are encountering is likely an error when trying to assign directly to an InArgument of an activity. I wrote a blog post about this Passing arguments to Workflow Activities (again)

Related

Error when adding scoped dependency and different 'arity'

I'm attempting to register the following:
services.AddScoped(typeof(IReadRepository<>), typeof(EfRepository<,>));
However I'm receiving this error message:
Error: Arity of open generic service type 'Harmony.Data.Common.Abstractions.IReadRepository1[T]' does not equal arity of open generic implementation type 'Harmony.Data.SqlServer.EfRepository2[T,TContext]'. (Parameter 'descriptors')
For the resolved to type, the first type param is to be passed as the type argument to IReadRepository. The second param is of type DbContext which has already been registered.
Is there some other trick I'm missing here?
Thank you!

OXygen Implementation of XQuery: Why Can't Path Expressions Return Attribute Values Directly?

Previous Stack questions indicate that in certain implementations of XQuery, returning attributes directly from a path expression (e.g. `$doc//#name') fails to display results and yields runtime errors:
Can't select XML attributes with Oxygen XQuery implementation; Oxygen XPath emits result
XQuery unable to select attribute
While attribute values can be returned using the string() or data() functions, I'm still confused as to why this limitation exists at all. The former link suggests that it is indeed the OXygen IDE itself, independent of the XQuery processor. However, when I try to return attributes directly I get the following runtime error message:
error: Failed to invoke method retrieveFirstChunk in class org.exist.xmlrpc.RpcConnection: org.xml.sax.SAXException:
Error SENR0001: attribute 'notBefore' has no parent element
Since this error message is from the processor, could the type of processor play a role? I'm using eXist-db as my data source and processor.
I don't know the specifics of the particular products involved, but the basic situation is that XQuery can return an attribute or sequence of attributes, but the standard XQuery 1.0 serialization methods can't display the value. For example a query like //#id will select a sequence of attributes all named "id" and there is no way of serializing this as XML. The "adaptive" serialization method was introduced in XQuery 3.1 largely as a response to this problem: it's designed to display the results in human-readable form, not to output well-formed XML.

Symfony Console Component - Tokens vs Arguments

I'm building a cli application with Symfony Console Component. I'm using several other libraries - Monolog among others. I use the logger to log information about the command being executed, exit statuses, etc.
I find that I cannot print or log input arguments that I pass to my command.
When I call $inputArgs = $event->getInput(); in my event listener, I get an object of Symfony\Component\Console\Input\ArgvInput class. This class provides a method to retrieve a value of an argument:
getArgument(string $name) Returns the argument value for a given
argument name.
This method will always return an empty array since 'arguments' are in fact 'tokens'. Here is a screenshot from a debug window:
This seems very misleading. I need to get the values stored in $tokens and I do not want to resort to the global $_SERVER array.
Why are 'arguments' introduced by addArgument() tokens ? And how could I access them without resorting to $_SERVER?

Cannot deserialize an object using a converter?

Given a JSON string of the form {"$type":"MyType, MyAssembly","seed":0"}, why can't JsonConvert.DeserializeObject utilize the JsonConverter associated with "MyType"?
I've tried decorating the MyType class with a [JsonConverter(typeof(MyType))] attribute. Doesn't work. The custom JsonConverter's ReadJson method is never called.
I've tried adding the custom converter to the serializer's settings Converters collection and made sure the CanConvert method returns true for 'MyType' and the CanRead method returns true. Doesn't work. Neither the converter's CanConvert nor its ReadJson method is ever called.
The DeserializeObject method needs to be able to deserialize a JSON string containing an object whose type is unknown at compile time, but whose type is embedded in the JSON object via the special "$type" member. So don't suggest using DeserializeObject<T> or point out that it works for members, whose type is identified in the contract before hand.
FYI, this problem generalizes to cases where the deserialization needs to identify the object type solely from the embedded "$type" member, so for example, it also fails to resolve a converter if the JSON object is in an untyped JSON array, not just at the top-level.
Basically, an object cannot survive a round trip through the serialization/deserialization process, because although the WriteJson method will be called for the Converter when SerializeObject is called, when you subsequently pass the JSON string to DeserializeObject, it fails to call the converter's ReadJson method, and instead constructs an new instance and uses the basic member population routines.

Invoke Method in WorkFlow expecting Optional Parameters to be passed?

I have method in Business Layer, which contains some optional parameters.
When I am trying to invoke the method from the WorkFlow 4.0, it is expecting me to pass
the optional parameters also.
Is there a way that I can avoid passing optional parameters to the method.
The method that I have is SendEmail(string emailTo, string domain, string smtpAdress = "POP");
When I call this method any where in the code.. I am just calling the method like
SendEmail("xx.com","PFE"), which is working fine
But in the Workflow..it gives a compilation error saying that
" 'BLEmail' does not have a public instance method named 'SendEmail' matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod 'InvokeMethod'."
When I am passing the optional parameter, it works fine..but it loses the whole concept of optional parameter.
Please help..
Thanks and appreciate your feedback.
Sam.
InvokeMethodActivity does not handle optional parameters. You have to provide all parameters regardless if they are optional or not.

Resources