开发者

System.Action not known in UnitTest untill explicitly defined

I got this weird problem where System.Action cant be resolved when its not explicitly defined above. To explain this in a better way i show you the code

    [TestMethod]
    public void Channel_Dispatch_Waits_Before_Return()
    {
        //Action useless = null;

        WorkflowChannel channel = new WorkflowChannel();
        bool isHandeled = false;

        channel.Subscribe(WorkflowHandlerFactory.FromLambdaAsync<int>((data, callback, onError) =>
        {
            // Go on another thread and sleep for a small ammount of time to simulate a async request
            System.Threading.ThreadPool.QueueUserWorkItem(state =>
            {
                System.Threading.Thread.Sleep(100);

                isHandeled = true;

                callback();
            });
        }));


        channel.Dispatch(1);

        Assert.IsTrue(isHandeled);
    }

This gives a compile time error, namely:

Error 1 Delegate 'Action' does not take 0 arguments C:\Users***\Documents\Visual Studio 2010\Projects\MessageWorkflow\MessageWorkfow.Test\WorkflowChannelTest.cs 47 21 MessageWorkflow.Test

However, when i uncomment the line:

Action useless = null;

It doesnt give a compile time error. I tried to rebuild etc but no use. If required, the declaration of: FromLambdaAsync is:

public static IWorkflowHandler FromLambdaAsync<T>(AsyncAction<T> method)

Where AsyncAction is:

public delegate void AsyncAction<T>(T message, Action onComplete, Action<Exception> onError);

Its not a showstopper but i'm confused since i cant find any logic behind this... Who can slap me in the face?

Cheers!

* EDIT *

I managed to reproduce this behavior in the most simple test case, see:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary2
{
    public delegate void AsyncAction(Action onComplete);

    public class WorkflowHandler
    {

    }

    public class Main
    {
        public static WorkflowHandler FromLambdaAsync(AsyncAction method)
        {
            return new WorkflowHandler();
        }
    }
}

With the unit test:

using ClassLibrary2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestProject1
{
    [TestClass]
    public class MainTest
    {
        [TestMethod()]
        public void FromLambdaAsyncTest()
        {
            Main.FromLambdaAsync((callback) =>
                {
                    callback();
                });
        }
    }
}

Which gives me the same开发者_运维技巧 error

The project is compiling against .NET 4.0 usign VS 2010 sp1

* EDIT 2: *

Simplified the test case even more, no change in the result

* EDIT 3 *

Even in the most simple test case this fails, see:

[TestMethod()]
public void FromLambdaAsyncTest()
{
    AsyncAction action = c => c();
}


Duplicated: see 'Delegate 'System.Action' does not take 0 arguments.' Is this a C# compiler bug (lambdas + two projects)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜