# 14.3.0 SkiaSharp System.AccessViolationException when loading in JPG

**URL:** <https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612>\
**Category:** WPF\
**Created:** [May 12, 2025, 7:38am UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612 "2025-05-12T07:38:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian\_Thoms](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Julian\_Thoms](https://community.thinkgeo.com/u/Julian_Thoms)\
**Post date:** [May 12, 2025, 7:38am UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/1 "2025-05-12T07:38:39Z")

</div>

Hi, using the current version **14.3.0** and SkiaSharp Version **3.116.1** I get an AccessViolationException when trying to load in a JPG file.  
Is this a known issue?

Here is the stacktrace:

```
|>|SkiaSharp.dll!SkiaSharp.SkiaApi.sk_pixmap_scale_pixels(System.IntPtr cpixmap, System.IntPtr dst, SkiaSharp.SKSamplingOptions* sampling) Line 7461|C#|
| |SkiaSharp.dll!SkiaSharp.SKPixmap.ScalePixels(SkiaSharp.SKPixmap destination, SkiaSharp.SKSamplingOptions sampling) Line 216|C#|
| |SkiaSharp.dll!SkiaSharp.SKBitmap.ScalePixels(SkiaSharp.SKPixmap destination, SkiaSharp.SKSamplingOptions sampling) Line 714|C#|
| |SkiaSharp.dll!SkiaSharp.SKBitmap.ScalePixels(SkiaSharp.SKBitmap destination, SkiaSharp.SKSamplingOptions sampling) Line 709|C#|
| |ThinkGeo.Core.dll!8RQ=.HBU=.JBU=(object image, int width, int height)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.GeoImage.Clip(ThinkGeo.Core.DrawingRectangle clippingRectangle, int clippingWidth, int clippingHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.NativeImageRasterSource.GetImageCore(ThinkGeo.Core.RectangleShape worldExtent, int canvasWidth, int canvasHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.RasterSource.GetImage(ThinkGeo.Core.RectangleShape worldExtent, int canvasWidth, int canvasHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.RasterLayer.DrawCore(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.Layer.BCA=(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.Layer.Draw(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.LayerTileView.DrawLayerAsync.AnonymousMethod__0()|Unknown|
```

---

<div class="post-metadata">

**Author:** ![Julian\_Thoms](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Julian\_Thoms](https://community.thinkgeo.com/u/Julian_Thoms)\
**Post date:** [May 12, 2025, 8:45am UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/2 "2025-05-12T08:45:42Z")

</div>

![image](https://community.thinkgeo.com/uploads/default/original/3X/9/0/90f6cf1f217b918748d521d012fd50b2b0b24e5c.png)

Translation: An attempt was made to read or write to the protected memory. This is often an indication that other memory is damaged.

---

<div class="post-metadata">

**Author:** ![Julian\_Thoms](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Julian\_Thoms](https://community.thinkgeo.com/u/Julian_Thoms)\
**Post date:** [May 12, 2025, 9:36am UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/3 "2025-05-12T09:36:29Z")

</div>

Here are the jpg files that causes the issue:

> **[LimeWire: Share Files - Secure File Upload Platform](https://limewire.com/?lmwr-ftv=1)**
>
> Upload and send files of any size quickly and securely. No account required to share your files, photos and videos.

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [May 12, 2025, 3:39pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/4 "2025-05-12T15:39:01Z")

</div>

Julian,

It seems your download link not working, can you send it again?

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [May 12, 2025, 3:49pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/5 "2025-05-12T15:49:33Z")

</div>

Hi Julian,

It seems they introduced an **AccessViolationException** in SkiaSharp v3, and it should have been fixed in the latest v3.119, here is the PR:

[Fix the SKImage.FromPicture implementation by mattleibow · Pull Request #3231 · mono/SkiaSharp · GitHub](https://github.com/mono/SkiaSharp/pull/3231)

Let me upgrade the Skia to the latest v3.119 in the latest beta branch and you then can have another try.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [May 12, 2025, 4:16pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/6 "2025-05-12T16:16:25Z")

</div>

All right, the latest beta (14.4.0-beta003) with SkiaSharp v3.119.0 is now available on Nuget, please have a try.

---

<div class="post-metadata">

**Author:** ![Julian\_Thoms](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Julian\_Thoms](https://community.thinkgeo.com/u/Julian_Thoms)\
**Post date:** [May 12, 2025, 5:27pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/7 "2025-05-12T17:27:35Z")

</div>

Hi, thanks for your help.

I tried the latest beta, sadly I still get the same **System.AccessViolationException** exception:

```
|>|SkiaSharp.dll!SkiaSharp.SkiaApi.sk_pixmap_scale_pixels(System.IntPtr cpixmap, System.IntPtr dst, SkiaSharp.SKSamplingOptions* sampling) Line 11900|C#|
| |SkiaSharp.dll!SkiaSharp.SKPixmap.ScalePixels(SkiaSharp.SKPixmap destination, SkiaSharp.SKSamplingOptions sampling) Line 199|C#|
| |SkiaSharp.dll!SkiaSharp.SKBitmap.ScalePixels(SkiaSharp.SKPixmap destination, SkiaSharp.SKSamplingOptions sampling) Line 704|C#|
| |SkiaSharp.dll!SkiaSharp.SKBitmap.ScalePixels(SkiaSharp.SKBitmap destination, SkiaSharp.SKSamplingOptions sampling) Line 698|C#|
| |ThinkGeo.Core.dll!8RQ=.HBU=.JBU=(object image, int width, int height)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.GeoImage.Clip(ThinkGeo.Core.DrawingRectangle clippingRectangle, int clippingWidth, int clippingHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.SkiaRasterSource.GetImageCore(ThinkGeo.Core.RectangleShape worldExtent, int canvasWidth, int canvasHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.RasterSource.GetImage(ThinkGeo.Core.RectangleShape worldExtent, int canvasWidth, int canvasHeight)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.RasterLayer.DrawCore(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.Layer.BCA=(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.Core.dll!ThinkGeo.Core.Layer.Draw(ThinkGeo.Core.GeoCanvas canvas, System.Collections.ObjectModel.Collection<ThinkGeo.Core.SimpleCandidate> labelsInAllLayers)|Unknown|
| |ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.LayerTileView.DrawLayerAsync.AnonymousMethod__0()|Unknown|

```

It seems like the forum link “onebox” cuts off the link after the #. It works when copying it in directly, please remove the space after /

[https://limewire.com/](https://limewire.com/) d/LqOu9#vnnPRSLtCR

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [May 12, 2025, 5:59pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/8 "2025-05-12T17:59:19Z")

</div>

Hi Julian,

I couldn’t recreate the issue with neither v14.3.0 nor v14.4.0-beta003, the following code works fine for me.

> private void mapView\_Loaded(object sender, RoutedEventArgs e)  
> {  
> mapView.MapUnit = GeographyUnit.Meter;
> 
> ```
> var layerOverlay = new LayerOverlay();
> mapView.Overlays.Add(layerOverlay);
> 
> var geoTiffRasterLayer = new SkiaRasterLayer(@"d:\Downloads\Stadtkarte_farbig_75\Stadtkarte_farbig_75.jpg");
> 
> //var geoTiffRasterLayer = new WpfRasterLayer(@"d:\Downloads\Stadtkarte_farbig_75\Stadtkarte_farbig_75.jpg");
> layerOverlay.Layers.Add(geoTiffRasterLayer);
> 
> geoTiffRasterLayer.Open();
> mapView.CurrentExtent = geoTiffRasterLayer.GetBoundingBox();
> _ = mapView.RefreshAsync();
> 
> ```
> 
> }

 ![image](https://community.thinkgeo.com/uploads/default/original/3X/6/5/65b2c7622da81f04573b48cf6db496e9b7095413.jpeg)

Can you send me your code snippet?

FYI: Besides SkiaRasterLayer, you can also use WpfRasterLayer, it’s specific for Desktop with better performance.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![Julian\_Thoms](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Julian\_Thoms](https://community.thinkgeo.com/u/Julian_Thoms)\
**Post date:** [May 13, 2025, 7:12am UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/9 "2025-05-13T07:12:14Z")

</div>

> [@Ben](#):
>
> WpfRasterLayer

Hi, thanks, are there any other special WPF layers that I should use? Or only this one?  
It works with WpfRasterLayer. I also tried the test jpgs in the HowDoI Project and they work, for whatever reason only some jpgs don’t work. I sadly don’t have a code snippet as this is a WPF application from 2003 and extremely huge and convoluted. The general structure looks like this:

I have a special ProjMap : MapView which defines two overlays, ShapefileOverlay and ImageOverlay (image is the same as below)

```
public LayerOverlay ShapefileOverlay
{
    get
    {
        if (!this.Overlays.Contains("ShapefileOverlay"))
        {
            this.Overlays.Add("ShapefileOverlay", new LayerOverlay());
            ((LayerOverlay)this.Overlays["ShapefileOverlay"]).DrawingQuality = DrawingQuality.HighSpeed;
        }

        return (LayerOverlay)this.Overlays["ShapefileOverlay"];
    }
}

```

The layers I define as special Layers as I need meta information on, so we have special classes for this.

```
public ViewerImageLayer(IViewerLayer layer)
{
     switch (layer.FileType)
     {
         case FileType.Tiff:
             this.MapLayer = new GeoTiffRasterLayer(this.FilePath);
              break;
          case FileType.JPG:
          case FileType.JPEG:
          case FileType.PNG:
              this.MapLayer = new WpfRasterLayer(this.FilePath);
              break;
}

```

with

```
public interface IViewerLayer
{
    ProjMap Map { set; }
    Layer MapLayer { get; set; }
    ... other meta info

```

Again, this is an extremely old application from 2003 which used a legacy ThinkGeo version, so if there’s anything obvious that is necessary / unnecessary I’d appreciate it 🙂

E.g. is it good practice to separate Shapes and Images in two different Layers? Or is that unnecessary and better to keep them in one?  
We have 3 Layers in total, one for Shapes, one for Images, and one for Temporary Highlights. We are increasing the amount of Layer Types that can be displayed (so adding WPF, WMS, File Geodatabases etc.) - how would the best way of structuring the Overlays be? Or just render everything in one & then the Temporary Highlights in the other?

Thanks Ben!

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [May 13, 2025, 4:28pm UTC](https://community.thinkgeo.com/t/14-3-0-skiasharp-system-accessviolationexception-when-loading-in-jpg/10612/10 "2025-05-13T16:28:46Z")

</div>

Hi Julian,

Here are the answers for your questions:

1. Raster layer types

- In ThinkGeo.Core, the built‑in `RasterLayer` uses SkiaSharp and works cross‑platform.
- `WpfRasterLayer` is the only “special WPF layer” we have at this time, it’s desktop‑only (WPF/WinForms) and have better performance.

1. About updating to the newer version

- My suggestion is to rebuild your project and address any ThinkGeo warnings. Those deprecation hints will point you to the new APIs in the latest ThinkGeo release.

1. Overlay strategy  
Q: Is it good practice to separate Shapes and Images in two different Layers? Or is that unnecessary and better to keep them in one?

- When to combine (one overlay):

- When to separate (multiple overlays):

1. Suggested overlay structure for your case

- You can put highlight layer to a separate overlay and all the other layers to one overlay. Because all the other layers are always refreshed at the same time, I suppose.
- You can consider putting WMS layer into its own overlay (or just use WmsOverlay instead) because WMS might be slow requesting the tiles, you don’t want it show down the other layers. Put it into a separate overlay so even the wms is slow, the other background layers will also be rendered.

Let us know if you have more questions.

Thanks,  
Ben
