Hi, This is very likely to be because System.Void is a special type and our Resolver ends up being confused.
You can use the module TypeSystem to get a reference to System.Void. Jb On Tue, Feb 4, 2020 at 3:59 PM digitalio Q <[email protected]> wrote: > Executing the following code, all the Resolve() methods works properly but > the last one; any idea why it fails? > > var resolver = new DefaultAssemblyResolver(); >> >> var asm = resolver.Resolve(new >> AssemblyNameReference("ClassLibrary1", new Version())); >> var module = asm.MainModule; >> var sysAsm = module.AssemblyReferences.First(cur => cur.Name >> == "netstandard"); >> >> // way 1 >> var ctorSource = >> typeof(SerializableAttribute).GetConstructor(Type.EmptyTypes); >> var ctorRef1 = module.ImportReference(ctorSource); >> var ctorDef1 = ctorRef1.Resolve(); >> if (ctorDef1 == null) >> throw new ApplicationException(); // doesn't throw >> >> // way 2 >> var returnType = new TypeReference("System", "Void", module, >> sysAsm); >> var returnTypeDef = returnType.Resolve(); >> if (returnTypeDef == null) >> throw new ApplicationException(); >> >> var attribType = new TypeReference("System", >> "SerializableAttribute", module, sysAsm); >> var attribTypeDef = attribType.Resolve(); >> if (attribTypeDef == null) >> throw new ApplicationException(); >> >> var ctorRef2 = new MethodReference(".ctor", returnType, >> attribType) >> { >> HasThis = true, >> }; >> ctorRef2 = module.ImportReference(ctorRef2); >> var ctorDef2 = ctorRef2.Resolve(); >> if (ctorDef2 == null) >> throw new ApplicationException(); // throws >> >> > -- > -- > -- > mono-cecil > --- > You received this message because you are subscribed to the Google Groups > "mono-cecil" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/mono-cecil/14b921f6-26de-456c-a9e9-b088f7ee12ae%40googlegroups.com > <https://groups.google.com/d/msgid/mono-cecil/14b921f6-26de-456c-a9e9-b088f7ee12ae%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- -- -- mono-cecil --- You received this message because you are subscribed to the Google Groups "mono-cecil" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mono-cecil/CABsHH9LAhWZniTDXBsrmr-%3D0OwhE7GKoH7v39Oa_qu_d3D-aog%40mail.gmail.com.
