I have created a new ASP.NET 5 MVC web application which hosts a razor class library with some .net blazor wasm components and a 3rd party library called Elsa. Everything seems to work OK, however when I try to load the Elsa homepage I get the following error:

TypeLoadException: Generic method or method in generic class is internal call, PInvoke, or is defined in a COM Import class.

Unknown location
TypeLoadException: Could not load type 'WebAssembly.JSInterop.JSCallInfo' from assembly 'Microsoft.JSInterop.WebAssembly, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.

Unknown location
ReflectionTypeLoadException: Unable to load one or more of the requested types.
Generic method or method in generic class is internal call, PInvoke, or is defined in a COM Import class.
Could not load type 'WebAssembly.JSInterop.JSCallInfo' from assembly 'Microsoft.JSInterop.WebAssembly, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.

System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)

Kind of lost on this one...not sure why regular MVC pages are loading, but not the 3rd party MVC libs. I believe Elsa was compiled for .NET Standard 2.1.

2

There are 2 answers

1
Sipke Schoorstra On BEST ANSWER

I can't know for sure, but every time I have seen this error in combination with Elsa 1 and its Dashboard services being added, it had to do with the auto discovery of activity types in order for them to be registered with the dashboard.

The reason Elsa tries to auto-register activities is to avoid you to having to register not only the activities you want to enable for the workflow host, but also the activities you want made available through the workflow designer.

But as you can see from this comment, it has issues.

For Elsa 1, there are basically 2 workarounds:

  1. Register each activity manually (see sample below)
  2. Copy the DiscoverActivities extension method and add more cases to skip loading types from assemblies starting with "WebAssembly" in their name.

The real fix however is provided by Elsa 2, which takes a completely different approach, by exposing the available activities via an API endpoint, which the workflow designer consumes to list activities from the activity picker. Which is clean, elegant, and robust.

To manually register activity types to be shown from the dashboard in Elsa 1, replace services.AddElsaDashboard() with:

services.AddElsaDashboard(dashboard => dashboard.Configure(options => options.ActivityDefinitions
    .Add<WriteLine>()
    .Add<ReadLine>()
    .Add<SendHttpRequest>()
    // etc.
));

Not great, but fortunately this has been fixed in Elsa 2.

0
gwruck On

For me, the problem was a missing reference to Microsoft.AspNetCore.Components.WebAssembly.DevServer in my client project.

I was upgrading a blazor server project to WASM and struck this error that took a while to debug.