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

Accessing Images from a .resource File in .NET 9.0 #12714

Closed
ElavazhaganSF4422 opened this issue Jan 6, 2025 · 3 comments
Closed

Accessing Images from a .resource File in .NET 9.0 #12714

ElavazhaganSF4422 opened this issue Jan 6, 2025 · 3 comments
Labels
binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it

Comments

@ElavazhaganSF4422
Copy link

.NET version

.NET 9.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, in the .NET 8.0 version, we were able to access the image from the .resource file.

Issue description

I added an image file as a resource in my project and attempted to access the image using the ResourceManager. However, when running the application in .NET 9.0 (NET90), I encountered the following error:

System.PlatformNotSupportedException: 'BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.'

Interestingly, this approach works successfully when using .NET 8.0 (NET80). Below are the screenshots showing the issue in NET90 and the successful result in NET80:

NET90 Error Screenshot:
Image

NET80 Success Screenshot:
Image

Request: I need an alternate solution for accessing the .resources file in .NET 9.0, as the BinaryFormatter is no longer supported in this version. How can I successfully load and access resources, such as images, in .NET 9.0?

Steps to reproduce

  1. Run the Sample
  2. click the button

New folder (2).zip

Observed behavior
Image

Excepted behavior
Image

@ElavazhaganSF4422 ElavazhaganSF4422 added the untriaged The team needs to look at this issue in the next triage label Jan 6, 2025
@SathiyathanamSathish
Copy link

SathiyathanamSathish commented Jan 6, 2025

@dotnet/dotnet-winforms - Does we have any alternate solution for this?

@JeremyKuhne
Copy link
Member

@SathiyathanamSathish can you please remove the tag for "everyone" in your comment above? That isn't actually tagging anyone involved with WinForms.

If you add your image resources via the "Resources File" template (which creates a .resx file where you can add the images), the embedded resource will be accessible without needing to take in the compatibility package. If you want to continue to use a pre-generated embedded resource file you'll need to use the compat package.

@JeremyKuhne JeremyKuhne added binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it 📭 waiting-author-feedback The team requires more information from the author and removed untriaged The team needs to look at this issue in the next triage labels Jan 6, 2025
@Zheng-Li01
Copy link
Member

@SathiyathanamSathish, the issue can be resolved as below screenshot, please have a try.
Image

@JeremyKuhne JeremyKuhne closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2025
@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback The team requires more information from the author label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it
Projects
None yet
Development

No branches or pull requests

4 participants