如何正确设置 Elsa?

发布于 2025-01-11 08:30:34 字数 1102 浏览 3 评论 0原文

这是我在 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"))
);

当我启动项目时,我收到此错误:

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

Mediatr 和 Elsa 的版本都是相同的,所以也许我遗漏了一些东西?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2025-01-18 08:30:34

您的代码看起来不错,但考虑到 TypeLoadException,尽管如此,很可能存在版本冲突。您提到 Mediatr 和 Elsa 的版本是相同的。如果确实如此,那么也许可以尝试以下操作:

有时,简单地清理应用程序的 bin 和 obj 文件夹也可以达到目的。有时,我发现旧的程序集用于构建,而不是新的程序集。

如果没有看到完整的上下文(即包含项目文件内容的整个解决方案),很难准确说出导致错误的原因,但根据我的经验,我发现有时人们认为所有 Elsa 版本都是相同的,但当我查看时,事实并非如此(有这么多 Elsa 包很容易被忽视)。

无论如何,如果你想不出来,我很乐意和你一起看看。你可以通过 Discord 联系我。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文