-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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.GetType("System.Net.Http.HttpClientHandler", false, true) does not find type but finds it when ignoreCase is set to false #65013
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsDescriptionWhen trying to do GetType with ignorecase as true does not find the type but finds it when ignoreCase is set to false. This only happens in .NET7 preview 1 and does not happen in .NET 6. PowerShell team is using the type in PowerShellGet and it fails to register the endpoint as the type is not found. Reproduction StepsSample program: public static void Main(string[] args) {
//string assemblyName = "System.Net.Http.dll";
//string typeName = "System.Net.Http.HttpClientHandler";
string assemblyName = args[0];
string typeName = args[1];
var myLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
string assemblyPath = Path.Join(myLocation, assemblyName);
var assembly = System.Reflection.Assembly.LoadFile(assemblyPath);
var typeWithCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: true);
if (typeWithCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: true)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: true): {typeWithCaseIgnore.FullName} ");
}
var typeWithoutCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: false);
if (typeWithoutCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: false)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: false): {typeWithoutCaseIgnore.FullName} ");
}
} Output: HelloWorld.exe System.Net.Http.dll System.Net.Http.HttpClientHandler But for some other type it works: HelloWorld.exe System.Xml.dll System.Xml.XmlTextReader Expected behavior
Actual behavior
Regression?Yes. Works with .NET 6 and below Known WorkaroundsUse ignoreCase as false, but might cause side effects Configuration.NET SDK (reflecting any global.json): Runtime Environment: Host (useful for support): Other informationNo response
|
I believe this is blocking powershell's release for p1. |
In addition to the issue in registering endpoints for gallery, PowerShell uses reflection to look up types using Assembly.GetType(, throwonError: false, ignoreCase: true). |
/cc @SteveL-MSFT as FYI |
Reflection libraries team did not touch the I tried the sample code with 6.0 sdk:
tried the same code with 7.0 sdk:
Seems something changed in |
Tagging subscribers to this area: @dotnet/area-infrastructure-libraries Issue DetailsDescriptionWhen trying to do GetType with ignorecase as true does not find the type but finds it when ignoreCase is set to false. This only happens in .NET7 preview 1 and does not happen in .NET 6. PowerShell team is using the type in PowerShellGet and it fails to register the endpoint as the type is not found. Reproduction StepsSample program: public static void Main(string[] args) {
//string assemblyName = "System.Net.Http.dll";
//string typeName = "System.Net.Http.HttpClientHandler";
string assemblyName = args[0];
string typeName = args[1];
var myLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
string assemblyPath = Path.Join(myLocation, assemblyName);
var assembly = System.Reflection.Assembly.LoadFile(assemblyPath);
var typeWithCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: true);
if (typeWithCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: true)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: true): {typeWithCaseIgnore.FullName} ");
}
var typeWithoutCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: false);
if (typeWithoutCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: false)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: false): {typeWithoutCaseIgnore.FullName} ");
}
} Output: HelloWorld.exe System.Net.Http.dll System.Net.Http.HttpClientHandler But for some other type it works: HelloWorld.exe System.Xml.dll System.Xml.XmlTextReader Expected behavior
Actual behavior
Regression?Yes. Works with .NET 6 and below Known WorkaroundsUse ignoreCase as false, but might cause side effects Configuration.NET SDK (reflecting any global.json): Runtime Environment: Host (useful for support): Other informationNo response
|
PowerShell is a standalone app and I believe System.Net.Http.dll comes with the SDK. So, if we build against .NET 7 SDK, we don't really have a choice but to get the .NET 7 version of the assembly. |
I don't think this is infrastructure related. I just doubled checked the As a note, I tried this on Windows 11 and macOS and it reproed on both OSs. Something interesting that I found that also tells me it has nothing to do with the assembly, is that if I change the type to search for to be
So it seems like maybe something changed in our string comparisons and it is hitting a bug where ignore case for the specific Adding @tarekgh as he might have some ideas. Also adding @ericstj as this is blocking the p1 release. |
We need someone from the runtime side to take a look. type system is what handle that runtime/src/coreclr/vm/assemblynative.cpp Line 376 in 3c43ef6
|
CC @VSadov |
This could be caused by some of the loader cleanup changes. |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsDescriptionWhen trying to do GetType with ignorecase as true does not find the type but finds it when ignoreCase is set to false. This only happens in .NET7 preview 1 and does not happen in .NET 6. PowerShell team is using the type in PowerShellGet and it fails to register the endpoint as the type is not found. Reproduction StepsSample program: public static void Main(string[] args) {
//string assemblyName = "System.Net.Http.dll";
//string typeName = "System.Net.Http.HttpClientHandler";
string assemblyName = args[0];
string typeName = args[1];
var myLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
string assemblyPath = Path.Join(myLocation, assemblyName);
var assembly = System.Reflection.Assembly.LoadFile(assemblyPath);
var typeWithCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: true);
if (typeWithCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: true)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: true): {typeWithCaseIgnore.FullName} ");
}
var typeWithoutCaseIgnore = assembly.GetType(typeName, throwOnError: false, ignoreCase: false);
if (typeWithoutCaseIgnore is null) {
Console.WriteLine("Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: false)");
}
else {
Console.WriteLine($"Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: false): {typeWithoutCaseIgnore.FullName} ");
}
} Output: HelloWorld.exe System.Net.Http.dll System.Net.Http.HttpClientHandler But for some other type it works: HelloWorld.exe System.Xml.dll System.Xml.XmlTextReader Expected behavior
Actual behavior
Regression?Yes. Works with .NET 6 and below Known WorkaroundsUse ignoreCase as false, but might cause side effects Configuration.NET SDK (reflecting any global.json): Runtime Environment: Host (useful for support): Other informationNo response
|
@safern I can't repro this at all, instead I get: Which is what I expect, because System.Net.Http.dll doesn't live next to the user assembly, which should be the entry assembly in the sample case. Did you modify the sample at all? |
The enumerator was missing the last 2 buckets Fixes dotnet#65013
Yes I did modify the repro. I changed the GetDirectoryName call to instead of using the executing assembly base directory to use: |
Here's a simplified repro that throws: var assembly = typeof(HttpClient).Assembly;
var typeName = "System.Net.Http.HttpClientHandler";
Console.WriteLine($"Type: {assembly.GetType(typeName, throwOnError: true, ignoreCase: false)}");
Console.WriteLine($"Type ignoreCase: {assembly.GetType(typeName, throwOnError: true, ignoreCase: true)}"); |
It looks like we've found the problem, and Jan has a fix at #65157 |
The enumerator was missing the last 2 buckets Fixes #65013
The enumerator was missing the last 2 buckets Fixes dotnet#65013
Description
When trying to do GetType with ignorecase as true does not find the type but finds it when ignoreCase is set to false.
This only happens in .NET7 preview 1 and does not happen in .NET 6.
PowerShell team is using the type in PowerShellGet and it fails to register the endpoint as the type is not found.
Reproduction Steps
Sample program:
Output:
HelloWorld.exe System.Net.Http.dll System.Net.Http.HttpClientHandler
Type NOT found with: assembly.GetType(typeName, throwOnError: false, ignoreCase: true)
Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: false): System.Net.Http.HttpClientHandler
But for some other type it works:
HelloWorld.exe System.Xml.dll System.Xml.XmlTextReader
Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: true): System.Xml.XmlTextReader
Type found with assembly.GetType(typeName, throwOnError: false, ignoreCase: false): System.Xml.XmlTextReader
Expected behavior
System.Net.Http.HttpClientHandler
is foundActual behavior
System.Net.Http.HttpClientHandler
is NOT foundRegression?
Yes. Works with .NET 6 and below
Known Workarounds
Use ignoreCase as false, but might cause side effects
Configuration
.NET SDK (reflecting any global.json):
Version: 7.0.100-preview.1.22107.7
Commit: fa575c5753
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: <>\AppData\Local\Microsoft\dotnet\sdk\7.0.100-preview.1.22107.7\
Host (useful for support):
Version: 7.0.0-preview.1.22076.8
Commit: 4053379
Other information
No response
The text was updated successfully, but these errors were encountered: