Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Client (WASM): unable to use SkiaSharp in .NET 6 #2640

Closed
1 task done
curia-damiano opened this issue Oct 5, 2023 · 15 comments
Closed
1 task done

Blazor Client (WASM): unable to use SkiaSharp in .NET 6 #2640

curia-damiano opened this issue Oct 5, 2023 · 15 comments
Labels

Comments

@curia-damiano
Copy link

Description

With the recent versions of .NET 6, it seems that something has changed and it is not possible to use SkiaSharp anymore.
Existing application that were previously running, once rebuild with latest versions of .NET 6 SDK, give errors at runtime (unable to load the SkiaSharp DLL).

Code

I attach a POC project that reproduces the problem.

Note: it works with .NET 7 SDK
If using the global.config to force to use the .NET 6 SDK, we get the wrong behavior

BlazorApp2.zip

Expected Behavior

I would expect to compile existing applications even from later versions of .NET 6

Actual Behavior

Instead we get this error in the browser console:

image

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

  • Windows 11
  • Browser: Chrome

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@curia-damiano
Copy link
Author

Additional comment: when compiling with Visual Studio 2022 17.5.2, the application works successfully
With later releases, it breaks at runtime.

@mattleibow
Copy link
Contributor

I see you mention that there is an update to .NET 6 SDK and you listed that there was a change in the version of SkiaSharp.

Did you update both at the same time? What happens if you use the same SkiaSharp with the new .NET 6 SDK?

@curia-damiano
Copy link
Author

Sorry for the confusion - that came from the template

The change has been in the update of Visual Studio. With 17.5.2, it works. With newer versions, no.
No changes of SkiaSharp - both tests use the latest available NuGet.

@mattleibow
Copy link
Contributor

@curia-damiano The changes are most likely in some part of the .NET SDK.

Are you able to run the following:

  • dotnet --info
  • dotnet workload --info

in the solution directory on both the working and not working setups? I am just wanting to verify the installed wasm-tools and sdk versions.

@Redth
Copy link
Contributor

Redth commented Oct 31, 2023

This appears to be due to some change in the IDE for how debugging a WASM Blazor application works with respect to handling native file references.

If you try dotnet run --project .\BlazorApp2\Client\BlazorApp2.Client.csproj in your sample, that does seem to work with .NET 6.0 SDK.

@curia-damiano
Copy link
Author

On the Azure VM with Visual Studio 17.5.2:

C:_WorksNB\BlazorApp2>dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.416
Commit: db3bc4a6c6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.416\

Host:
Version: 7.0.4
Architecture: x64
Commit: 0a396acafe

.NET SDKs installed:
6.0.416 [C:\Program Files\dotnet\sdk]
7.0.202 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
C:_WorksNB\BlazorApp2\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

@curia-damiano
Copy link
Author

On the Azure VM with Visual Studio 17.5.2:

C:_WorksNB\BlazorApp2>dotnet workload list

Installed Workload Ids Manifest Version Installation Source

wasm-tools 6.0.24/6.0.400 SDK 6.0.400

Use dotnet workload search to find additional workloads to install.

@marcpopMSFT
Copy link

Is it an option to use the 7.0 SDK for this? I see that you're on 17.5 VS which is out of support. If you upgraded to the in-support 17.6 VS and use the in-support 7.0.3xx SDK, you can use that to target 6.0 applications. The 6.0.416 SDK you're using was meant to be used with 17.3. While we don't block mismatching the SDK and VS versions, we can't test every combination and every scenario.

Here's some more details on that: https://learn.microsoft.com/en-us/dotnet/core/porting/versioning-sdk-msbuild-vs#lifecycle

@curia-damiano
Copy link
Author

On my machine, with latest VS installations:

C:_WorksNB\BlazorApp2>dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.416
Commit: db3bc4a6c6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.416\

Host:
Version: 8.0.0-rc.2.23479.6
Architecture: x64
Commit: 0b25e38ad3

.NET SDKs installed:
6.0.416 [C:\Program Files\dotnet\sdk]
7.0.403 [C:\Program Files\dotnet\sdk]
8.0.100-rc.1.23463.5 [C:\Program Files\dotnet\sdk]
8.0.100-rc.2.23502.2 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-rc.1.23420.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
C:_WorksNB\BlazorApp2\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

@curia-damiano
Copy link
Author

On my machine, with latest VS installations:

C:_WorksNB\BlazorApp2>dotnet workload list

Installed Workload Ids Manifest Version Installation Source

wasm-tools 6.0.22/6.0.400 SDK 6.0.400

Use dotnet workload search to find additional workloads to install.

Updates are avaliable for the following workload(s): wasm-tools. Run dotnet workload update to get the latest.

@curia-damiano
Copy link
Author

curia-damiano commented Oct 31, 2023

Is it an option to use the 7.0 SDK for this? I see that you're on 17.5 VS which is out of support. If you upgraded to the in-support 17.6 VS and use the in-support 7.0.3xx SDK, you can use that to target 6.0 applications. The 6.0.416 SDK you're using was meant to be used with 17.3. While we don't block mismatching the SDK and VS versions, we can't test every combination and every scenario.

Here's some more details on that: https://learn.microsoft.com/en-us/dotnet/core/porting/versioning-sdk-msbuild-vs#lifecycle

Hi,
The 7.0 SDK works.
But from https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history Visual Studio 2022 17.5.2 is still current.
And the customer needs to run it on .NET 6, that is LTS.

And in fact, the real problem is that the issue happens with latest versions of Visual Studio. With the older version 17.5.2 it works.
My customer would like to upgrade its version of Visual Studio.

@curia-damiano
Copy link
Author

This appears to be due to some change in the IDE for how debugging a WASM Blazor application works with respect to handling native file references.

If you try dotnet run --project .\BlazorApp2\Client\BlazorApp2.Client.csproj in your sample, that does seem to work with .NET 6.0 SDK.

I confirm that running this command on my machine with all latest VS installations, IT WORKS !!!

So it's definitely a Visual Studio issue, more than a SDK issue.

This is already a very good result for my customer.

Now, are you able to forward this issue to the Visual Studio team?

@mattleibow
Copy link
Contributor

Is this an option? #2640 (comment)

Is it an option to use the 7.0 SDK for this? I see that you're on 17.5 VS which is out of support. If you upgraded to the in-support 17.6 VS and use the in-support 7.0.3xx SDK, you can use that to target 6.0 applications. The 6.0.416 SDK you're using was meant to be used with 17.3. While we don't block mismatching the SDK and VS versions, we can't test every combination and every scenario.

Here's some more details on that: https://learn.microsoft.com/en-us/dotnet/core/porting/versioning-sdk-msbuild-vs#lifecycle

@lewing
Copy link
Member

lewing commented Oct 31, 2023

When you set your TargetFramework to net6.0 you will build a net6.0 (LTS) application even when using a 7.0.xxx SDK version. The problem you are hitting is a previously unknown incompatibility with workloads when using global.json to force a 6.0.xxx version of the sdk with recent VisualStudio versions.

Our recommendation is that you use the SDK that comes with the Visual Studio you want to use (remove global.json) and continue to target net6.0. That will resolve the problem you are hitting and still produce a net6.0 LTS application.

@curia-damiano
Copy link
Author

Thank you for your support, it is really appreciated!

My customer will probably keep the global.json, but upgrading it to use the .NET 7 SDK solves the issue.

We will keep it in this way, until migration to .NET 8.

Closing this issue I want to thank all of your again for your quick support.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants