Solution for “XamlInjector–Cannot create unknown type errors” does not work

孤人 提交于 2019-12-10 11:46:44

问题


In unit test, i passed the assembly of Custom Activity to the ctor as the local assembly var xamlInjector = new XamlInjector("CreditAtRenewalFlow.xaml", typeof(CreateFollowUp).Assembly);

CreateFollowUp is a AsynCodeActivity

I got error "'Unexpected 'PROPERTYELEMENT' in parse rule 'Element ::= . EmptyElement | ( StartElement ElementBody ).'.' Line number '2' and line position '4'." at execution of the following line

var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

The sample of the unit test is [TestMethod] [DeploymentItem(@"src\ProcessFlows\Activity1.xaml")] public void Activity1Test() {

    var xamlInjector = new XamlInjector("Activity1.xaml", typeof(CreateFollowUp).Assembly);
    xamlInjector.ReplaceAll(typeof(CreateFollowUp), typeof (MockCreateFollowUp));

    var mockExternalServiceManager = new Mock<IExternalServices>();
    mockExternalServiceManager.Setup(x => x.CreateFollowUp()).Verifiable();

    var host = WorkflowInvokerTest.Create(xamlInjector.GetActivity());

    dynamic parameterValues1 = new WorkflowArguments();
    parameterValues1.value1 = mockExternalServiceManager.Object;

    IDictionary<string, object> dictionary = host.TestActivity();

   }

And the CreateFollowUp is given below

public sealed class CreateFollowUp : AsyncCodeActivity {
[RequiredArgument] public InArgument ExternalServices { get; set; }

    protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback,

object state) { Action createFollowUp = this.ExternalServices.Get(context).CreateFollowUp; context.UserState = createFollowUp; return createFollowUp.BeginInvoke(callback, state); }

    protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
    {
        var createFollowUp = context.UserState as Action;
        if (createFollowUp == null)
        {
            throw new ArgumentNullException("The AsyncState of the IAsyncResult was not of the type

ExternalServices.AsyncCreateFollowUp.", (Exception)null); }

        createFollowUp.EndInvoke(result);
    }
}

回答1:


try to modify source code of the activity. Change "xmlns:local="clr-namespace:Activity1" to xmlns:local="clr-namespace:Activity1;assembly=Activity1".

include the assembly in namespaces references (use the correct assembly name)



来源:https://stackoverflow.com/questions/9743133/solution-for-xamlinjector-cannot-create-unknown-type-errors-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!