Skip to content

Conversation

@steveisok
Copy link
Member

Adjust AppContext.BaseDirectory to return "/" for wasm because GetEntryAssembly().Location returns an empty string.

This change also enables most of the Microsoft.Extensions.* tests with the exception of DependencyModel and Hosting.

Steve Pfister added 3 commits July 2, 2020 11:19
…ryAssembly().Location returns an empty string.

This change also enables most of the Microsoft.Extensions.* tests with the exception of DependencyModel and Hosting.
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

{
// Fallback path for hosts that do not set APP_CONTEXT_BASE_DIRECTORY explicitly
string? directory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
if (directory != null && !Path.EndsInDirectorySeparator(directory))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the null check only one and return Empty here

{
// GetEntryAssembly().Location returns an empty string for wasm
// Until that can be easily changed, work around the problem here.
return "/";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add explicit test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I think it's acceptable to just rely on the tests that use this property to pass.

private static string GetBaseDirectoryCore()
{
// GetEntryAssembly().Location returns an empty string for wasm
// Until that can be easily changed, work around the problem here.
Copy link
Member

@jkotas jkotas Jul 3, 2020

Choose a reason for hiding this comment

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

How is this working around GetEntryAssembly().Location returning empty string?

Would it make more sense for BaseDirectory to be empty string as well when there is no file system?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps the wording is incorrect. AppContext.BaseDirectory is returning "", which is causing a bunch of tests to fail. I feel returning "/" isn't any less wrong than "". The benefit of "/" being that it works within other parts of libraries.

Copy link
Member

@jkotas jkotas Jul 3, 2020

Choose a reason for hiding this comment

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

I think that returning "/" is more wrong than "".

If we were optimizing for making maximum tests to pass without any changes, we would also change Assembly.Location to return /<assemblyname>.dll that would be even more wrong.

What are the tests that fail before this change and pass with this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll follow up with a list.

Since the emscripten vfs mounts at /, I think my change does make sense.
https://emscripten.org/docs/porting/files/file_systems_overview.html

Copy link
Member

Choose a reason for hiding this comment

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

Do the application binaries show up as files at / ?

The docs for AppContext.BaseDirectory say: Gets the pathname of the base directory that the assembly resolver uses to probe for assemblies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here are the tests that fail expecting some sort of value out of BaseDirectory.

Regarding application binaries, my understanding is that we load everything essentially from an in-memory byte array. That strikes me as an implementation detail though. If the user, for example, downloads Foo.dll and stores it in the VFS, probing at /Foo.dll would be expected.

I still think setting "/" is the way to go. That said, there definitely does seem to be a bunch of little hosting twists that we should try to understand / surface better.

Copy link
Member

Choose a reason for hiding this comment

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

Do the types exercised by there tests actually work on Wasm Browser? E.g. can I add configuration file to my .csproj file and then get the file picked up by the default IFileProvider at runtime?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. If you look at the test results, we're likely at least somewhat functional.

https://gist.github.com/steveisok/370622cdb0c41ff2bc3b439c730484e4

Copy link
Member

@jkotas jkotas Jul 6, 2020

Choose a reason for hiding this comment

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

I think we should have issues opened on making sure that the end-to-end works for these libraries. More passing tests does not necessarily mean that these libraries are actually usable by customers.

The linker analysis for single file unfriendly APIs (#38405) should help us get a better handle on this eventually.

If you believe that returning / here is going to help to make the affected scenarios work end-to-end, I can live with it.

Steve Pfister added 2 commits July 6, 2020 16:02
[ConditionalFact]
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be removed as well, it doesn't do anything useful anymore since this is about the old .NET Framework-based Mono. We can do that in a separate PR, filed #38878.

@steveisok steveisok merged commit 806aee0 into dotnet:master Jul 7, 2020
@steveisok steveisok deleted the extensions-wasm-work branch July 7, 2020 17:25
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-System.Runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants