'How do I setup Elsa correctly?

This is my code in Program.cs

var builder = WebApplication.CreateBuilder(args);

var elsaSection = builder.Configuration.GetSection("Elsa");
// Elsa services.
builder.Services.AddElsa(elsa => elsa
    .UseEntityFrameworkPersistence(ef => ef.UseSqlServer(builder.Configuration.GetConnectionString("Database")))
    .AddConsoleActivities()
    .AddHttpActivities(elsaSection.GetSection("Server").Bind)
    .AddQuartzTemporalActivities()
    .AddWorkflowsFrom<Program>()
);
//Elsa API endpoints.
builder.Services.AddElsaApiEndpoints();

// Allow arbitrary client browser apps to access the API.
// In a production environment, make sure to allow only origins you trust.
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy
    .AllowAnyHeader()
    .AllowAnyMethod()
    .AllowAnyOrigin()
    .WithExposedHeaders("Content-Disposition"))
);

And when I start the project I get this error:

System.TypeLoadException: 'Could not load type 'MediatR.INotification' from assembly 'MediatR, Version=10.0.0.0

The versions of Mediatr and Elsa are all the same, so maybe I am missing something?



Solution 1:[1]

Your code looks good, but given the TypeLoadException, there is most likely a version conflict despite. You mention that the versions of Mediatr and Elsa are the same. If that's really the case then maybe try the following:

Sometimes a simple cleanup of your bin and obj folders of the application can do the trick as well. On occasion, I found that older assemblies are being used for the build, rather than fresh ones.

It's hard to say exactly what is causing the error without seeing full context (i.e. your entire solution with project file contents), but in my experience, I have found that sometimes one thinks that all Elsa versions are the same, and yet when I looked, this was not the case (it's easy to overlook with so many Elsa packages).

In any case, if you can't figure it out I am happy to have a look with you. You can reach me on Discord.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sipke Schoorstra