-
Notifications
You must be signed in to change notification settings - Fork 585
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
Importer create ClassSig rather than GenericInstSig for generic type #462
Comments
If you have time, find the line in dnlib code, get the git blame and check why the line was changed. https://github.com/0xd4d/dnlib/blame/master/src/DotNet/Importer.cs |
This code is from: dnlib/src/DotNet/ReflectionExtensions.cs Lines 57 to 58 in aa403ba
Seems the line wasn't changed. When I modify it to:
I'll get StackOverflowException somewhere (not above code) |
A generic instance is not a generic type def so both checks are needed. This does not appear to be a dnlib issue. |
But the type inside |
It's a problem that reflection is lying about it. If you can detect it some other way, let me know. There's another method in the same file that's used by some other code that can be used if you pass in some boolean flag. |
I'm sorry, I made a mistake:
So, reflection keep pace with Task.ContinueWith So, reflection isn't lying? |
@wtfsck Can you view this issue |
Hello! namespace TestFile {
public sealed class Program {
public static void Main() {
var resolver = new AssemblyResolver();
resolver.DefaultModuleContext = new ModuleContext(resolver);
var mod = ModuleDefMD.Load(typeof(Program).Assembly.Location, resolver.DefaultModuleContext);
var type = mod.Find("TestFile.Program", true);
var method = type.FindMethod("TestMethod");
var operand = (IField)method.Body.Instructions.FirstOrDefault(x => x.OpCode.Code == Code.Ldsfld).Operand;
Console.WriteLine("Original: {0}", operand);
var reflectionMember = (FieldInfo)typeof(Program).Assembly.ManifestModule.ResolveMember(operand.MDToken.ToInt32());
var importer = new Importer(mod, ImporterOptions.TryToUseDefs, GenericParamContext.Create(method));
Console.WriteLine("Imported: {0}", importer.Import(reflectionMember));
Console.ReadKey(true);
}
private static void TestMethod() {
Console.WriteLine(GenericClass<NonGenericClass.NestedGenericStruct<Type>>.Field);
}
}
internal sealed class GenericClass<V> {
private GenericClass() { }
public static readonly GenericClass<V> Field = new GenericClass<V>();
}
internal static class NonGenericClass {
public struct NestedGenericStruct<K> { }
}
} Compiling and running this code with dnlib 3.5.0 yields the following result:
It is worth mentioning that doing the same using dnlib 3.4.0 yield the expected result:
I think something got broken when this PR #452 by @wwh1004 was merged which modified how fields are imported. |
Seems
|
PRs welcome. I don't have time. |
In old commit 4ebebc1#diff-3bc1d65c9144274297f0e9a1b2e194898aa3aa9e441d2956ab303ab4522dc554L488 code is var fieldSig = new FieldSig(ImportAsTypeSig(origField.FieldType)); So I use "origField" instead of "fieldInfo". But after running more tests I find "fieldInfo" is true. |
I don't know if it's a .NET runtime bug or dnlib bug.
.NET runtime indicate different
IsGenericTypeDefinition
for the same typeTask<>
dnlib create ClassSig since
IsGenericType
andIsGenericTypeDefinition
are bothTrue
;The text was updated successfully, but these errors were encountered: