senzacionale
senzacionale

Reputation: 20936

Error CS0832 An expression tree may not contain an assignment operator

public class ConsoleRegistry : Registry
{
    public ConsoleRegistry()
    {
        Scan(scan =>
        {
            scan.TheCallingAssembly();
            scan.WithDefaultConventions();
        });

        For<IJobFactory>().Use<StructureMapJobFactory>();

        For<ISchedulerFactory>().Use(ctx => new StdSchedulerFactory());
        /*For<IScheduler>().Use(async delegate (IContext ctx)
        {
            var scheduler = await ctx.GetInstance<ISchedulerFactory>().GetScheduler();
            scheduler.JobFactory = ctx.GetInstance<IJobFactory>();
            return scheduler;
        });*/

        ForSingletonOf<IScheduler>().Use(ctx =>
        {
            IScheduler scheduler = ctx.GetInstance<ISchedulerFactory>().GetScheduler().Result;
            scheduler.JobFactory = ctx.GetInstance<IJobFactory>();
            return scheduler;
        });
    }

What is wrong with last ForSingletonOf<IScheduler>()...?

I am getting this error

Error CS0832 An expression tree may not contain an assignment operator

Upvotes: 2

Views: 1470

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727057

This sounds like a bug somewhere in the implementation of the library. Since the project is “sunsetted,” you are unlikely to get a fix, so try working around it by introducing a helper method:

private static IScheduler MakeScheduler(IContext ctx) {
    ... // the code from your lambda goes here
}
...
ForSingletonOf<IScheduler>().Use(ctx => MakeScheduler(ctx));

Upvotes: 1

Related Questions