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

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

Merged
merged 17 commits into from
Aug 15, 2020

Conversation

agocke
Copy link
Member

@agocke agocke commented Aug 9, 2020

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
@ghost
Copy link

ghost commented Aug 9, 2020

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
Copy link
Member Author

agocke commented Aug 10, 2020

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
Member

That is really weird - does it repro locally?

@@ -425,6 +431,12 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? vers

public override FileStream[] GetFiles(bool getResourceModules)
{
if (Location == "")
Copy link
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).

Copy link
Member

@steveisok steveisok Aug 10, 2020

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
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
Copy link
Member Author

agocke commented Aug 10, 2020

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

@@ -425,6 +431,12 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? vers

public override FileStream[] GetFiles(bool getResourceModules)
{
if (Location == "")
Copy link
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
Copy link
Member Author

agocke commented Aug 12, 2020

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

@steveisok
Copy link
Member

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

@CoffeeFlux
Copy link
Contributor

Definitely strange. I'll take a look tomorrow.

@agocke
Copy link
Member Author

agocke commented Aug 13, 2020

@CoffeeFlux Any luck?

@CoffeeFlux
Copy link
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
Copy link
Member Author

agocke commented Aug 14, 2020

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

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

@@ -490,6 +490,12 @@ public void IsEnumDefined_Invalid()
[InlineData(typeof(CompoundClass4<string>), new Type[] { typeof(GenericInterface1<string>), typeof(TI_NonGenericInterface1) })]
public void ImplementedInterfaces(Type type, Type[] expected)
{
if (PlatformDetection.IsMonoRuntime)
Copy link
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
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
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?

Copy link
Contributor

@wzchua wzchua Aug 15, 2020

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
Copy link
Member

jkotas commented Aug 15, 2020

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
Copy link
Member Author

agocke commented Aug 15, 2020

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
Copy link
Member

jkotas commented Aug 15, 2020

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
Copy link
Member

jkotas commented Aug 15, 2020

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