Skip to content

Change Assembly.GetFile(s) to throw when in-memory - #40593

Merged
jkotas merged 17 commits into
dotnet:masterfrom
agocke:throw-in-getfiles
Aug 15, 2020
Merged

jkotas merged 17 commits into
dotnet:masterfrom
agocke:throw-in-getfiles

Conversation

@agocke

@agocke agocke commented Aug 9, 2020 •

Copy link
Copy Markdown
Member

This code path already threw an exception in most cases, but mostly accidentally.
This changes the code to deliberately throw an exception when the assembly is
in-memory.

Fixes #40154

This is technically a breaking change, although a minor one, as the
previous behavior also threw an exception. The previous exception was
an IOException and this is an InvalidOperationException, so if users
were catching the previous exception they would not succeed now.

Fixes dotnet#40154
@agocke agocke added the area-AssemblyLoader-coreclr only use for closed issues label Aug 9, 2020
@ghost

ghost commented Aug 9, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

@agocke
agocke requested a review from vitek-karas August 9, 2020 22:01
@agocke

agocke commented Aug 10, 2020

Copy link
Copy Markdown
Member Author

This is a little strange -- I seem to have somehow changed the order that interface implementations here are returned. Not sure how that could have happened. Ideas?

@vitek-karas

Copy link
Copy Markdown
Member

That is really weird - does it repro locally?


public override FileStream[] GetFiles(bool getResourceModules)
{
if (Location == "")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe file an issue that this code should move to the shared corelib - for example the GetFiles is basically identical (just different coding style a bit).

@steveisok steveisok Aug 10, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree. /cc @CoffeeFlux in case I'm missing anything.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this should be able to move, just have to keep in mind that changing the layout is hard because we want to match the legacy mono BCL in some cases (or at least, having them differ would result in a bunch of netcore-specific runtime code).

@agocke

agocke commented Aug 10, 2020

Copy link
Copy Markdown
Member Author

Huh, it still seems like interfaces have been re-ordered somehow, but I can't seem to get the mono tests to run locally


public override FileStream[] GetFiles(bool getResourceModules)
{
if (Location == "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this should be able to move, just have to keep in mind that changing the layout is hard because we want to match the legacy mono BCL in some cases (or at least, having them differ would result in a bunch of netcore-specific runtime code).

@agocke

agocke commented Aug 12, 2020

Copy link
Copy Markdown
Member Author

@danmosemsft I'm stuck on this Mono issue. Can you recommend someone to help out?

@steveisok

Copy link
Copy Markdown
Member

@CoffeeFlux the mono test failures look weird. Any thoughts?

@CoffeeFlux

Copy link
Copy Markdown
Contributor

Definitely strange. I'll take a look tomorrow.

@agocke

agocke commented Aug 13, 2020

Copy link
Copy Markdown
Member Author

@CoffeeFlux Any luck?

@CoffeeFlux

Copy link
Copy Markdown
Contributor

Interestingly, these pass locally for me even with the debug configuration.

./build.sh mono+libs -c debug
./dotnet.sh build src/libraries/System.Reflection/tests/ /t:Test /p:Configuration=Debug

gives me

  ----- start Fri Aug 14 17:22:09 EDT 2020 =============== To repro directly: =====================================================
  pushd /Users/ryan/git/runtime/artifacts/bin/System.Reflection.Tests/net5.0-Debug
  /Users/ryan/git/runtime/artifacts/bin/testhost/net5.0-OSX-Debug-x64/dotnet exec --runtimeconfig System.Reflection.Tests.runtimeconfig.json  xunit.console.dll System.Reflection.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing 
  popd
  ===========================================================================================================
  ~/git/runtime/artifacts/bin/System.Reflection.Tests/net5.0-Debug ~/git/runtime/src/libraries/System.Reflection/tests
    Discovering: System.Reflection.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Reflection.Tests (found 390 of 407 test cases)
    Starting:    System.Reflection.Tests (parallel test collections = on, max threads = 12)
    Finished:    System.Reflection.Tests
  === TEST EXECUTION SUMMARY ===
     System.Reflection.Tests  Total: 1278, Errors: 0, Failed: 0, Skipped: 0, Time: 1.369s
  ~/git/runtime/src/libraries/System.Reflection/tests
  ----- end Fri Aug 14 17:22:12 EDT 2020 ----- exit code 0 ----------------------------------------------------------

@agocke

agocke commented Aug 14, 2020

Copy link
Copy Markdown
Member Author

@CoffeeFlux The same is true for me. Should I temporarily disable this test?

@CoffeeFlux

Copy link
Copy Markdown
Contributor

Yeah, let's disable it for now. I'm trying to get the artifacts off CI so I can figure out what's actually going on here, and maybe I'll get somewhere this weekend—think I'm done for today though. If I can't get it sorted out this weekend and it ends up being a serious issue, I'll figure out the backport.

[InlineData(typeof(CompoundClass4<string>), new Type[] { typeof(GenericInterface1<string>), typeof(TI_NonGenericInterface1) })]
public void ImplementedInterfaces(Type type, Type[] expected)
{
if (PlatformDetection.IsMonoRuntime)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the proper way to exclude this is to open an issue on Github with the specifics and then apply the ActiveIssue attribute to the method? That file has another example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this condition since ActiveIssue is added?

@wzchua wzchua Aug 15, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has been fixed as part of #40632

@jkotas

jkotas commented Aug 15, 2020

Copy link
Copy Markdown
Member

Tests failing on wasm:

System.IO.FileNotFoundException : This assembly does not have a file table because it was loaded from memory.

Stack trace
   at System.Reflection.RuntimeAssembly.GetFiles(Boolean getResourceModules)
   at System.Reflection.Assembly.GetFiles()
   at System.Reflection.Tests.AssemblyTests.GetFiles()

@agocke

agocke commented Aug 15, 2020

Copy link
Copy Markdown
Member Author

Hmm, I'll claim that this is the right behavior -- wasm is basically load from memory. But how do I exclude these tests from running on wasm?

@jkotas

jkotas commented Aug 15, 2020

Copy link
Copy Markdown
Member

You can either mark them with PlatformDetection.IsNotBrowser.

Or you can make the test robust against assemblies loaded from memory in general case and suppress the failing checks when Location is empty string. It would be nice to be able to run all tests in single file mode eventually, even outside Browser.

@jkotas

jkotas commented Aug 15, 2020

Copy link
Copy Markdown
Member

Opened #40885 on the test failure

@jkotas
jkotas merged commit c73371d into dotnet:master Aug 15, 2020
@agocke
agocke deleted the throw-in-getfiles branch August 15, 2020 18:43
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-AssemblyLoader-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assembly.GetFile should throw an explicit exception for memory-loaded assemblies

9 participants