Skip to content

net 5 Cannot read resources that depend on serialization #48159

Closed

Description

@LiorBanai

Hi,
We moved to net 5.0.3 (from net 5) and now we are getting thea above exception in Winform form in the Designer on lines like:

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.btnOpenProtocolsFolder.Image = ((System.Drawing.Image)(resources.GetObject("btnOpenProtocolsFolder.Image")));

what could e the reason?

Activity

  1. ghost added
    untriaged
    on Feb 11, 2021
  2. filipnavara commented on Feb 11, 2021

    @filipnavara
    Member

    This question was cross-posted to dotnet/winforms (dotnet/winforms#4556) and answered there. I don't think it requires any action in this repository. However, the NotSupportedException is misleading because the deserialization actually works. The issue is that an underlying FileNotFoundException is hidden from the API consumer and makes it much harder to diagnose what is going on.

  3. filipnavara commented on Feb 11, 2021

    @filipnavara
    Member

    Suggestion: area-System.Resources

    cc @ericstj @stephentoub w.r.t. the unhelpful exception that has totally incorrect message:

    // If serialization isn't supported, we convert FileNotFoundException to
    // NotSupportedException for consistency with v2. This is a corner-case, but the
    // idea is that we want to give the user a more accurate error message. Even if
    // the dependency were found, we know it will require serialization since it
    // can't be one of the types we special case. So if the dependency were found,
    // it would go down the serialization code path, resulting in NotSupported for
    // SKUs without serialization.
    //
    // We don't want to regress the expected case by checking the type info before
    // getting to Type.GetType -- this is costly with v1 resource formats.
    catch (FileNotFoundException)
    {
    throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization);
    }

    Even wrapping the FileNotFoundException as InnerException would be helpful because now it's invisible unless the debugger has the Just my code option turned off (it's on by default).

  4. LiorBanai commented on Feb 11, 2021

    @LiorBanai
    Author

    @filipnavara Thanks!

  5. ericstj commented on Feb 11, 2021

    @ericstj
    Member

    I have reactivated the WinForms issue because what the designer is doing is broken.

    I think we can update the inner exception here.

  6. filipnavara commented on Feb 11, 2021

    @filipnavara
    Member

    @ericstj There's another WinForms issue (dotnet/winforms#4528) where I filed the detailed description earlier. And yet another one that I filed for another version tolerant issues that's moved in the private dotnet/winforms-designer repository. I was told that it's on the WinForms team radar now but I appreciate any help with getting it resolved once and for all.

  7. removed
    untriaged
    on Feb 11, 2021
  8. added this to the 6.0.0 milestone on Feb 11, 2021
  9. joperezr commented on Feb 11, 2021

    @joperezr
    Member

    Sounds good, I'll add the inner exception then so that it doesn't get thrown away.

  10. added
    enhancement
    on Feb 11, 2021
  11. 4 remaining items

  12. Budsy commented on May 5, 2021

    @Budsy

    In this case I didn't even publish this .NET 5 Windows Application at all. I made an Installer project in the same VS solution to put the whole shebang on the target computer. (It's still beta, and will work on trimming later). It works fine when installed and run on my development machine, but not when installed and run on the production box using the same installer. So this seems to show that the Icon resource data is included in the installer data I think. I'll have to look a little more at this. The target machine is an Azure VM Windows Server, so there's a possible significant difference there compared to my Windows 10 development environment.

  13. modified the milestones: 6.0.0, 7.0.0 on Jul 8, 2021
  14. ericstj commented on Jul 27, 2022

    @ericstj
    Member

    It works fine when installed and run on my development machine

    There's a feature in the host that will load missing assemblies from the NuGet cache, which would be present on your dev machine. I'm pretty sure you're hitting a file not found here like the original report. You could prove that by debugging the installed app and looking for the caught FileNotFoundException, or just procmon it to find the missing file. My guess is that it is System.Drawing.Common.dll. It's entirely possible that there is some other relevant inner exception here.

    @joperezr can we make the fix to add the appropriate inner exception here so that it will be easier for folks to debug?

  15. ghost added
    in-pr
    on Jul 27, 2022
  16. joperezr commented on Jul 27, 2022

    @joperezr
    Member

    Sure, sent out #72957 to address this.

  17. self-assigned this
    on Aug 3, 2022
  18. Repository owner moved this from Future to Done in Triage POD for Reflection, META, etc.on Aug 5, 2022
  19. ghost removed
    in-pr
    on Aug 5, 2022
  20. ghost locked as resolved and limited conversation to collaborators on Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Resourcesenhancement

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions