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

Assembly.CodeBase returns nonexistent path for assemblies from single-file #40087

Closed
vitek-karas opened this issue Jul 29, 2020 · 9 comments
Closed

Comments

@vitek-karas
Copy link
Member

  • Assembly.CodeBase
  • Assembly.EscapedCodeBase
  • AssemblyName.CodeBase
  • AssemblyName.EscapedCodeBase

all these APIs when called on an assembly loaded from single file return nonexistent path - basically as if the assembly file lives next to the executable.

The question is what is the correct behavior:

  • empty string - similar to Assembly.Location
  • The executable path - this would be logically similar to the behavior of in-memory loaded assemblies which return location of CoreLib as their CodeBase/EscapedCodeBase even though Assembly.Location returns empty string
@vitek-karas vitek-karas added this to the 5.0.0 milestone Jul 29, 2020
@ghost
Copy link

ghost commented Jul 29, 2020

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

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jul 29, 2020
@vitek-karas
Copy link
Member Author

/cc @MichalStrehovsky @jkotas

I don't know what the intent is for CodeBase/EscapedCodeBase APIs, so it's hard to tell what the correct behavior should be.
I know we're making them obsolete in .NET 5, but that still doesn't mean they should not work.

@jkotas
Copy link
Member

jkotas commented Jul 29, 2020

I don't know what the intent is for CodeBase/EscapedCodeBase APIs

The original intent for these APIs was to return URL to use for Code Access Security checks. E.g. if the assembly was downloaded from internet, these APIs can return http://something.

I do not have a strong opinion about what to do about these for single file.

@jkotas
Copy link
Member

jkotas commented Jul 29, 2020

Returning empty string sounds most reasonable to me.

@agocke
Copy link
Member

agocke commented Jul 29, 2020

In the single-file case, even corelib will likely be in the bundle and so have an empty string location, so empty string seems most consistent and simplest to understand. I also don't have strong feelings.

@MichalStrehovsky
Copy link
Member

From .NET Native experience:

This API is similar to the Assembly.Location API - the Location API has empty string as a documented value on MSDN and .NET Native used that. We got a lot of questions about this API and bug reports (failure in a NuGet package that the developer is not able to root cause that we then later root caused to not handling the empty string and using it for stuff that later ended up with NullReferenceException within the NuGet).

For CodeBase, .NET Native just threw PlatformNotSupportedException and we didn't receive any questions about this as far as I know. Empty string is not a documented value here. We would need to update the doc.

I would just go with throwing an exception with a message. We are obsoleting the APIs; no need to spend more energy on things like updating docs.

@jkotas
Copy link
Member

jkotas commented Jul 30, 2020

Good point. Throwing from APIs like this makes diagnostic a lot easier.

@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Aug 6, 2020
@agocke agocke modified the milestones: 5.0.0, 6.0.0 Aug 14, 2020
@agocke
Copy link
Member

agocke commented Aug 17, 2020

One complication: we've apparently doc'd the behavior when the assembly is loaded as a byte array:

If the assembly was loaded as a byte array, this property returns the location of the caller of the Load(Byte[]) method overload, not the location of the loaded assembly.

Obviously in the bundle case every case would be loaded from a byte array, so this behavior isn't well specified, but I'm not sure how we would deal with this in the code.

@agocke
Copy link
Member

agocke commented Aug 11, 2021

All of these APIs throw in 5.0 and 6.0

@agocke agocke closed this as completed Aug 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants