Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MaximLipnin opened this issue Feb 3, 2020 · 4 comments · Fixed by #32560, #33117 or mono/mono#19112
Assignees
Labels
area-AssemblyLoader-mono runtime-mono specific to the Mono runtime

Comments

@MaximLipnin
Copy link
Contributor

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)
@maryamariyan maryamariyan added area-System.Reflection untriaged New issue has not been triaged by the area owner and removed area-System.Reflection labels Feb 3, 2020
@jkotas jkotas added area-AssemblyLoader-mono runtime-mono specific to the Mono runtime labels Feb 5, 2020
@CoffeeFlux
Copy link
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

@danmoseley
Copy link
Member

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.

@danmoseley
Copy link
Member

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.)

@CoffeeFlux
Copy link
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).

@CoffeeFlux CoffeeFlux self-assigned this Feb 10, 2020
monojenkins pushed a commit to monojenkins/mono that referenced this issue Mar 2, 2020
Fixes dotnet/runtime#31649
Fixes dotnet/runtime#31650

**Testing**:
Reproduced Error via
`<Runtime Repo Root>/build.sh /p:RuntimeFlavor=mono`
Removing `[ActiveIssue("dotnet/runtime#31650", TestRuntimes.Mono)]` in AssemblyTests.cs
Running `dotnet msbuild /t:RebuildAndTest /p:XunitMethodName=System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException`

Fixing issue resulted in no errors.
monojenkins pushed a commit to monojenkins/mono that referenced this issue Mar 9, 2020
Fixes dotnet/runtime#31649
Fixes dotnet/runtime#31650

**Testing**:
Reproduced Error via
`<Runtime Repo Root>/build.sh /p:RuntimeFlavor=mono`
Removing `[ActiveIssue("dotnet/runtime#31650", TestRuntimes.Mono)]` in AssemblyTests.cs
Running `dotnet msbuild /t:RebuildAndTest /p:XunitMethodName=System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException`

Fixing issue resulted in no errors.
mdh1418 added a commit to mono/mono that referenced this issue Mar 10, 2020
Fixes dotnet/runtime#31649
Fixes dotnet/runtime#31650

**Testing**:
Reproduced Error via
`<Runtime Repo Root>/build.sh /p:RuntimeFlavor=mono`
Removing `[ActiveIssue("dotnet/runtime#31650", TestRuntimes.Mono)]` in AssemblyTests.cs
Running `dotnet msbuild /t:RebuildAndTest /p:XunitMethodName=System.Reflection.Tests.AssemblyTests.LoadFile_NoSuchPath_ThrowsFileNotFoundException`

Fixing issue resulted in no errors.

Co-authored-by: mdh1418 <mdh1418@users.noreply.github.com>
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.