Skip to content

[mono] Test failed on Helix: System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException #31650

Closed

Description

@MaximLipnin

System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException fails on Helix. It will be skipped with ActiveIssue in #2087.

    System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException [FAIL]
      Assert.Contains() Failure
      Not found: /home/helixbot/work/A55808B3/w/992A08DD/e/41ab3668ee15411ab49704619372e9f2
      In value:  Invalid Image
      Stack Trace:
           at System.AssertExtensions.ThrowsContains[FileNotFoundException](Action action, String expectedMessageContent)
           at System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException()
           at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Activity

  1. added
    untriaged
    and removed on Feb 3, 2020
  2. CoffeeFlux commented on Feb 7, 2020

    @CoffeeFlux
    Contributor

    We seem to throw the correct exception, but the test is failing because the error message itself does not contain the filename and instead has it specified below. This seems unnecessarily strict (though our message isn't great), but if we really want the path included in both places it should be an easy enough fix.

    Sample program:

    using System;
    using System.Reflection;
    using System.IO;
    
    namespace HelloWorld
    {
        class Program
        {
            static void Main(string[] args)
            {
                string rootedPath = Path.GetFullPath(Guid.NewGuid().ToString("N"));
                Console.WriteLine(rootedPath);
                Assembly.LoadFile(rootedPath);
            }
        }
    }

    Mono/CoreCLR output:

    ryan@kenshin:~/git/runtime/src/mono/netcore$ make run-sample-coreclr
    /Users/ryan/git/runtime/.dotnet/dotnet run -c Debug -p sample/HelloWorld
    /Users/ryan/git/runtime/src/mono/netcore/b2505d63f1334c23ab1081e6a9ad738e
    Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly '/Users/ryan/git/runtime/src/mono/netcore/b2505d63f1334c23ab1081e6a9ad738e'. The system cannot find the file specified.
    
    File name: '/Users/ryan/git/runtime/src/mono/netcore/b2505d63f1334c23ab1081e6a9ad738e'
       at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
       at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
       at System.Reflection.Assembly.LoadFile(String path)
       at HelloWorld.Program.Main(String[] args) in /Users/ryan/git/runtime/src/mono/netcore/sample/HelloWorld/Program.cs:line 13
    make: *** [run-sample-coreclr] Error 134
    ryan@kenshin:~/git/runtime/src/mono/netcore$ make run-sample
    /Users/ryan/git/runtime/.dotnet/dotnet msbuild /t:PatchLocalMonoDotnet /p:CoreClrTestConfig=Release /p:Configuration=Debug ../mono.proj
    Microsoft (R) Build Engine version 16.6.0-preview-20071-03+4400fa4e1 for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    COMPlus_DebugWriteToStdErr=1 ../../../.dotnet-mono/dotnet run -c Debug -p sample/HelloWorld
    /Users/ryan/git/runtime/src/mono/netcore/91adbc16a9bc4d40b000352dae4f4021
    
    Unhandled Exception:
    System.IO.FileNotFoundException: Invalid Image
    File name: '/Users/ryan/git/runtime/src/mono/netcore/91adbc16a9bc4d40b000352dae4f4021'
       at System.Runtime.Loader.AssemblyLoadContext.InternalLoadFromPath(String assemblyPath, String nativeImagePath)
       at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
       at System.Reflection.Assembly.LoadFile(String path)
       at HelloWorld.Program.Main(String[] args)
    [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Invalid Image
    File name: '/Users/ryan/git/runtime/src/mono/netcore/91adbc16a9bc4d40b000352dae4f4021'
       at System.Runtime.Loader.AssemblyLoadContext.InternalLoadFromPath(String assemblyPath, String nativeImagePath)
       at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
       at System.Reflection.Assembly.LoadFile(String path)
       at HelloWorld.Program.Main(String[] args)
    make: *** [run-sample] Error 1
    
  3. removed
    untriaged
    on Feb 7, 2020
  4. danmoseley commented on Feb 10, 2020

    @danmoseley
    Contributor

    I think I made the CoreCLR change -- where we have the file, we put it in the message, and where it's in the message, ToString doesn't bother repeating it on the next line. The reasoning behind this (beyond compact is nice) is that it's common to see an exception stringized into a log, and sometimes logs contain output from several concurrent activities that can get interleaved (eg., build logs). Having the value on the same line as the message keeps them together. I did something similar for some others, eg the argument for ArgumentException.

  5. danmoseley commented on Feb 10, 2020

    @danmoseley
    Contributor

    Having said that, I can't find such a change, but that's the philosophy. (It's good to have the file name in FileName, also in the message, and ToString should only show the latter.)

  6. CoffeeFlux commented on Feb 10, 2020

    @CoffeeFlux
    Contributor

    Makes sense to me. It's an easy enough change and I don't see any harm in it, so if you want to leave the tests I'll add it to our messages (and maybe clean them up a bit in the process - I'm not a big fan of just "Invalid Image" everywhere).

  7. self-assigned this
    on Feb 10, 2020
  8. added a commit that references this issue on Mar 10, 2020
    9ce7798
  9. ghost locked as resolved and limited conversation to collaborators on Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-AssemblyLoader-monoruntime-mono

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions