Different Resource Names between NetFramework48 and Net8
.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.
With a namespace matching the path in the project, both net48 and net8 can load the resource.
@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.
We offer you two options
1.
Remove namespace (.FormsTest) in Form1.cs and Form1.designer.cs
2.
Add icon to the project.
Change the code
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
which leads us to two workarounds
- making projectname, foldername and filename match exactly to namespace and typename.
- 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!
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?
@merriemcgaw - multitargeting an important scenario to enable migration to .NET, should we move this issue to the designer repo and investigate further?
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 - what happens when you change the .NET Framework project format to SDK style?
@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
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.
@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.)
Create a designer issue to track this, and closed this issue.