winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Different Resource Names between NetFramework48 and Net8

Open CortiWins opened this issue 1 year ago • 10 comments

.NET version

Net8.0-windows, Net Framework 4.8

Did it work in .NET Framework?

Yes

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

No response

Issue description

While upgrading an application to multitarget of both Net8 and classic Net48, i encountered an issue. The icon on a form, (saved as a ressource in the forms resx) did load correctly on Net8 but caused an exception on net48.

Form.InitializeComponent()
...->
Icon = (Icon)resources.GetObject("$this.Icon");      
...->   
System.Resources.MissingManifestResourceException

Steps to reproduce

I tried to recreate the issue in an example problem but it did not happen, so i used ILSpy to check the ressources in the assembly of the application and noticed that they do have different names between the net48 assembly and the net8 assembly, and the difference is the namespace.

This allowed me to recreate the error in the example application.( see attachment ) MultitargetRessourceProblem.zip

In ILSpy it looks like this. As you can see, Net8 includes the Namespace into the resource name, while net4 does not. grafik

With a namespace matching the path in the project, both net48 and net8 can load the resource.

CortiWins avatar Oct 03 '24 18:10 CortiWins

@LeafShi1 - could your team please investigate a workaround, I guess we can define resources in the project file explicitly instead of relying on the designer generated code.

Tanya-Solyanik avatar Oct 08 '24 18:10 Tanya-Solyanik

We offer you two options

1.

Remove namespace (.FormsTest) in Form1.cs and Form1.designer.cs

2.

Add icon to the project. Image Change the code Image

Epica3055 avatar Oct 10 '24 08:10 Epica3055

During the last days i created a workaround for us that solves it for us for now. Doing that made me realize that my previous description of net8 including the namespace is not 100% specific.

net8 uses the namespace/formtypename net 48 uses projectname/foldername/formfilename Image

which leads us to two workarounds

  1. making projectname, foldername and filename match exactly to namespace and typename.
  2. set the form icon in code. from project ressources, from embeddedData or something else.

So as mentioned i made a workaround that works for us. So this is not a cry for help but just a plain old bug report, with a fancy image so not even that plain.

Have a nice day everyone!

CortiWins avatar Oct 10 '24 20:10 CortiWins

This issue doesn't reproduce in separate NetFramework48 project or separate Net8 project, it only occurs when set multi target frameworks in a project <TargetFrameworks>net8.0-windows;net48</TargetFrameworks>

@Tanya-Solyanik This looks like a build issue, do we need to investigate this further?

LeafShi1 avatar Oct 11 '24 01:10 LeafShi1

@merriemcgaw - multitargeting an important scenario to enable migration to .NET, should we move this issue to the designer repo and investigate further?

Tanya-Solyanik avatar Oct 11 '24 20:10 Tanya-Solyanik

This issue doesn't reproduce in separate NetFramework48 project or separate Net8 project, it only occurs when set multi target frameworks in a project <TargetFrameworks>net8.0-windows;net48</TargetFrameworks>

From my tests, it is not the multitargeting. If i set the project that has the problem in multitarget to <TargetFramework>net48</TargetFramework> instead of multitarget, the probem still exists.

A new NetFramework48 project still uses the old project file format, while the problem happens in projects with a net SDK project file.

CortiWins avatar Oct 12 '24 12:10 CortiWins

@CortiWins - what happens when you change the .NET Framework project format to SDK style?

Tanya-Solyanik avatar Oct 13 '24 05:10 Tanya-Solyanik

@CortiWins - what happens when you change the .NET Framework project format to SDK style?

Net SDK style created with 8.0, TargetFramework changed to 4.8 -> error Net Framework 4.8 Updated via the Update Wizard to 8.0, TargetFramework changed to 4.8 -> error

CortiWins avatar Oct 14 '24 09:10 CortiWins

I'll leave this issue out here for the ongoing discussion, but I agree that multitargeting is getting to be a more and more important scenario. Let's talk in the team meeting about what we want to devote to this area.

merriemcgaw avatar Oct 14 '24 22:10 merriemcgaw

@Olina-Zhang can you open a designer issue for us to track making this less of a hassle in the future? (And close this one once you have.)

JeremyKuhne avatar Oct 22 '24 18:10 JeremyKuhne

Create a designer issue to track this, and closed this issue.

Zheng-Li01 avatar Oct 24 '24 02:10 Zheng-Li01