When I use mapsui in a standard wpf mvvm c# project, everything works fine, but when I try to use the mapsui map in a revit addin, I get the following error:
Method not found: "SkiaSharp.SKPicture SkiaSharp.SKPicture.Deserialize(System.ReadOnlySpan`1<Byte>)".
Exception: System.MissingMethodException: Method not found: "SkiaSharp.SKPicture SkiaSharp.SKPicture.Deserialize(System.ReadOnlySpan`1<Byte>)".
at Mapsui.Rendering.Skia.BitmapHelper.LoadBitmap(Object bitmapStream)
at Mapsui.Rendering.Skia.RasterStyleRenderer.Draw(SKCanvas canvas, Viewport viewport, ILayer layer, IFeature feature, IStyle style, IRenderCache renderCache, Int64 currentIteration)
I use the exact same versions of mapusi and it dependencies in the revit addin as in the standard wpf project.
All other objects (like geometries from geojsons or other) are shown correctly, only WMS services (images) cause this error.
What could be the reason for this error?
The most likely cause is a .dll conflict. Basically either some other addin or Revit itself is loading some different version of that assembly reference, and that version does not have the method you are referencing.
In your code, you can check the assembly version and location by doing something like this:
var version = typeof(SkiaSharp.SKPicture).Assembly.ImageRuntimeVersion;
var loadedDllPath = typeof(SkiaSharp.SKPicture).Assembly.Location;
The kicker is that you cannot really change or control which assemble gets loaded first if it is indeed a conflict, and even if you do, you might break something else. This is always going to be an issue for plugins in any application, since you can only load a single assembly into the Global Assembly Cache for an executing application. Revit's API has additional handling to ensure that this is the case, and it gives preferential treatment to the .dlls that it needs to load. This ensure that the main app will always load .dlls that won't cause issues for Revit itself.
Since SkiaSharp is an open source project, probably the easiest way to handle this is to create a fork of that repo and then create a build with a new name. There are other options out there, but they are all at least a little more complicated.