dotnet / dotnet/dotnet-api-docs
Assembly.LoadFrom treats parameter as path rather than URI
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
## Description
`Assembly.LoadFrom` is supposed to take a URI as its parameter:
> The `assemblyFile` parameter must refer to a URI without escape characters. This method supplies escape characters for all invalid characters in the URI.
([docs.microsoft.com](https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadfrom))
On .NET Framework, you can pass in a `file://` URI (constructed from the `Assembly.CodeBase` URI of another assembly, for example) to `Assembly.LoadFrom` and the assembly will be loaded.
On .NET Core, the `assemblyFile` parameter is treated as a path. The URI gets passed into `Path.GetFullPath` which mangles the URI to begin with and continues to treat it as a path from there on. This never works for loading an assembly from any URI.
https://github.com/dotnet/runtime/blob/a92f4f02dcbbd76cb9edf682424d001b9eb6d870/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs#L329-L334
For `file://` URIs, the behavior of .NET Core should match the behavior of .NET Framework, which is also the documented behavior. I don't have any opinions about whether this should work for non-`file://` URIs.
## Test Case
```c#
System.Reflection.Assembly.LoadFrom(typeof(object).Assembly.CodeBase)
````
On .NET Framework, this returns `[mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]`. On .NET Core, this throws `FileNotFoundException` with a message like `Could not load file or assembly 'C:\YourProject\bin\Debug\netcoreapp2.1\file:\C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.19\System.Private.CoreLib.dll'. The filename, directory name, or volume label syntax is incorrect.`.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start with src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs around lines 329-334 and reproduce the issue using Assembly.LoadFrom(typeof(object).Assembly.CodeBase). Compare the file:// behavior with the documented .NET Framework behavior; done when the URI loads without the shown FileNotFoundException.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100