Skip to content

Loader-related error messages are *extremely* unhelpful. #101298

Closed as not planned

Description

@masonwheeler

The purpose of an error message is to convey 1) something went wrong, 2) here's the problem, 3) here's what can be done about it. And for the most part, .NET error messages do a great job of it. While some can be a bit cryptic, (if I had a dollar for every time I've explained to a new developer what "object reference not set to an instance of an object" means...) they tend to be straightforward and helpful, and they've been improving in recent years, such as dictionary errors telling you which key it was that's not found.

One area really stands out as an exception, though: the loader. Error messages from it tend to provide little-to-nothing in the way of useful information, and it would be really nice if we could get some improvements on that for .NET 9.

For example, if you try to load foo.dll, which tries to load bar.dll, which tries to load baz.dll, and loading baz.dll fails because the file exists but it's not a valid assembly, the error message should tell you that. Instead, you're told that something went wrong loading foo.dll or one of its dependencies.

Likewise, if there's anything wrong with the IL or metadata of a type, the error message tells you, "System.TypeLoadException: 'Could not load type 'MyType' from assembly 'MyAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.'" Well... OK. Now what? The type "could not load." What exactly are you supposed to do with that knowledge? How are you supposed to go about debugging this problem?

Would it be possible to put some actionable details into error messages coming from the loader? This would be immensely helpful to those of us working on various flavors of code generation. (And if exposing some details could potentially have security ramifications of some sort, would it be possible to limit the scope of it with some sort of "only show details in debug builds" rule? Even if I don't want to show these details to end-users, I really, really want them for myself when I'm running my own code on my own system.)

Activity

  1. ghost added
    area-AssemblyLoader-coreclr
    on Apr 19, 2024
  2. added
    untriaged
    on Apr 19, 2024
  3. jkotas commented on Apr 19, 2024

    @jkotas
    Member

    For example, if you try to load foo.dll, which tries to load bar.dll, which tries to load baz.dll, and loading baz.dll fails because the file exists but it's not a valid assembly, the error message should tell you that. Instead, you're told that something went wrong loading foo.dll or one of its dependencies.

    It is not what I see.

    This issue is not actionable. Could you please separate issues for the specific error messages would like to see improved, with steps to reproduce the problem?

  4. added
    needs-author-action
    on Apr 19, 2024
  5. masonwheeler commented on Apr 19, 2024

    @masonwheeler
    ContributorAuthor

    @jkotas Oh wow, OK, umm... how many do you want? And is it possible to turn this into a "parent issue" to file all of the examples I come up with as sub-issues of?

  6. removed
    needs-author-action
    on Apr 19, 2024
  7. danmoseley commented on Apr 19, 2024

    @danmoseley
    Contributor

    @masonwheeler you could start by opening one to address what you believe is the most important case to fix.

  8. masonwheeler commented on Apr 19, 2024

    @masonwheeler
    ContributorAuthor

    @danmoseley Honestly, I don't particularly see it that way. From my perspective, this is a systemic problem of "error messages in the loader code are very unhelpful" that really ought to be reviewed top-to-bottom. Any examples I give would be just that, examples of the broad problem, rather than individual cases or bugs to be fixed.

    I'm happy to provide examples. But I'd really prefer to have them be treated as examples, not as individual cases where the problem is considered fixed once they have been individually resolved.

  9. masonwheeler commented on Apr 20, 2024

    @masonwheeler
    ContributorAuthor

    There you go. 3 examples. I'll drop more as I come across them.

  10. jkotas commented on Apr 20, 2024

    @jkotas
    Member

    Thank you!

    None of the issues that you have filled are loader related. One is in reflection, one is in reflection.emit, and one is by design - use ilverify.

    Given that, I think this issue can be closed. It does not make sense to have a parent issue for bad error messages across the whole runtime.

  11. masonwheeler commented on Apr 20, 2024

    @masonwheeler
    ContributorAuthor

    Getting back to the very start, I'm a bit surprised by when you said "It is not what I see." about the dependency-loading error. What do you see in a case like this? Because the generic error saying that it was unable to load the top-level DLL or one of its dependencies is the only thing I have ever seen when anything at all goes wrong with loading a dependent assembly.

  12. jkotas commented on Apr 20, 2024

    @jkotas
    Member

    I see assembly that actually failed to load referenced in the error message.

    We got rid of the "one of its dependencies" in the assembly loading error message 8 years ago: 32897f1#diff-b6c965d03da2236b9dc8e0cbd2ce4bcffd3bc87ab73c659b0f3d2591dc058800R998 . If you see "one of its dependencies" in the assembly load error message, you are either running on .NET Framework or you are confusing it with error message for native libraries load errors. The error message for native libraries load errors still has the "one of its dependencies". The OS APIs for loading native libraries do not tell you the exact native library that failed to load, so it is the best we can do. We include all detailed that the OS API for loading native libraries provides in the error message.

  13. removed
    untriaged
    on Apr 22, 2024
  14. locked and limited conversation to collaborators on May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-AssemblyLoader-coreclr

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions