locked
Re-hosted Windows Workflow 4.5 Designer “type '???' not found” and “Option Strict On disallows implicit conversions from '???' to '???'" RRS feed

  • Question

  • I have a re-hosted Windows Workflow Designer in a WPF application that dynamically generates POCOs using the Roslyn compiler and then dynamically loads them into the designer using the AssemblyContextControlItem.

    My issue is that types are available for selection in the "Browse for types" dialog, and can be assigned as the variable type in the Workflow Designer, however, when I try to use the POCOs in an expression (say a simple assignment to a List), I receive one of the two expression compilation messages (tool tip of the little red check mark):

    "Option Strict On disallows implicit conversions from '???' to '???' where '???' is the same type name"

    or

    "type '???' not found"

    The code to add the reference to the assemblies is:

    var acci = designer.Context.Items.GetValue<AssemblyContextControlItem>() ?? new AssemblyContextControlItem();
    if (!acci.ReferencedAssemblyNames.Contains(asm.GetName()))
    {
        AssemblyName name = asm.GetName();
        acci.ReferencedAssemblyNames.Add(name);
        designer.Context.Items.SetValue(acci);
    }

    The code to import the namespace:

    var acci = designer.Context.Items.GetValue<AssemblyContextControlItem>() ?? new AssemblyContextControlItem();
    var import = new VisualBasicImportReference() { Assembly = asm.GetName().Name, Import = "MyNamespace" };
    vbs.ImportReferences.Add(import);
    VisualBasic.SetSettings(root, vbs);

    All POCOs are in the same namespace. There is a DLL for each individual POCO.

    This previously worked without issue when the POCOs were generated in the same assembly, but breaking them into individual DLLs presents me with the "type '???' not found error or the "Option Strict On disallows implicit conversions from '???' to '???' where '???' is the same type name" error.

    I have looked at the DLLs with the Telerik JustDecompiler .NET de-compiler and the POCOs appear to be generated correctly and are in the correct namespace.

    I have also put the types back into a single DLL and the re-hosted designer picks up the types correctly and can be assigned as normal.

    The generated DLLs have been verified to be the same .NET version as the re-hosted designer target framework (4.5.1).

    The "Imported Namespaces" correctly shows the namespace of the POCOs. I’ve also tried to find information about both of these errors in relation to Windows Workflow and have come up empty.

    I don't understand why the types are available in the type browser, but then the Workflow can't assign them in an expression.

    Would anyone have any experience or ideas how to solve this issue?


    • Edited by Mr Shannon Monday, January 4, 2016 2:15 AM encoding
    Monday, January 4, 2016 2:03 AM

Answers

  • "Option Strict On disallows implicit conversions from '???' to '???' where '???' is the same type name"


    Hello,

    According to the error message, you have tried to convert a type to another type that may not be able to contain the value.

    To correct this issue:

    • Determine whether a conversion of any type exists from <type1> to <type2>. If both are Visual Basic elementary types, or if both are instances of classes, you can usually make this determination by consulting the table in Widening and Narrowing Conversions (Visual Basic).

    • If only a narrowing conversion exists from <type1> to <type2>, you should use explicit casting. The CType Function (Visual Basic) and DirectCast Operator (Visual Basic) keywords throw a run-time exception if the conversion fails. The TryCast Operator (Visual Basic) keyword applies only to reference types and returns Nothing (Visual Basic) if the conversion fails.

    • If a narrowing conversion exists and your program can tolerate a run-time failure, or you are confident that a run-time failure is not possible, you can specify Option Strict Off at the beginning of your source code. But you should still enclose the conversion in a Try...Catch...Finally Statement (Visual Basic) block to avoid unexpected results or early termination of your program.

    • If no conversion exists from <type1> to <type2>, you must re-evaluate your program logic. You might be able to write code that can assign values to <type2> corresponding to anticipated values of <type1>.

    • If no conversion exists from <type1> to <type2> and one of the types is a class or structure you have defined, you might be able to define a conversion operator from that type to or from the other type. For more information, see How to: Define a Conversion Operator (Visual Basic).

    • In all cases and as a general guideline, you should avoid using narrowing conversions unless you can trap failures in a Catch block and deal with them effectively.

    Regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Angie Xu Thursday, January 28, 2016 1:41 AM
    • Marked as answer by Angie Xu Thursday, January 28, 2016 1:41 AM
    Friday, January 22, 2016 2:27 AM