Okay, let me try to explain it again, and this time giving a specific example. I want to attach, say, DescriptionAttribute to an assembly I'm modifying. I need to attach the version of that attribute which is compatible with that assembly's target framework version (changing the target framework, even if I wanted to do this, probably isn't possible in this case). In order to do this, I must get a TypeReference to this attribute's type. I'm having trouble getting a TypeReference to the correct version of the attribute that comes from the correct assembly. Whatever I do, I can only manage to get a reference to the newer type (the one that is referenced by my modifying assembly).
On Monday, July 27, 2015 at 3:30:05 PM UTC+3, Jb Evain wrote: > > Hey Greg, > > I'm not 100% sure I understand your description of the issue, but you > can't use a type defined in a newer version of the .NET framework in > an assembly targeting an older version. > > Is this what you're trying to do? > > If so, you'll need to change the target framework for the assembly, > and fix up its references to the newer version, but it can get hairy > if you're using 3rd party assemblies. > > Jb > > > > On Sun, Jul 26, 2015 at 6:20 PM, Greg Rosenbaum <[email protected] > <javascript:>> wrote: > > Hey there. I've sort of run into a problem, and I'm wondering if anyone > can > > help me. > > > > I'm trying to modify an assembly that uses framework version 3.5, but I > > don't want to be limited to that framework myself. I want to embed some > > attributes into it, and to do that I need to get references to their > types, > > from the correct assembly version. The attributes are standard .NET > > attributes and their assemblies live in the GAC. > > > > I can't seem to manage to do that. I can't import my own types, because > > they're from a higher version assembly, and I trying to get the correct > > assembly by name (using Module.AssemblyResolver.Resolve), doesn't seem > to > > work, even if I specify the exact version I want. It just resolves the > wrong > > assembly. > > > > The only thing that seemed to work was using > > System.Reflection.Assembly.ReflectionOnlyLoad to load the assembly from > its > > AssemblyName (version + name), and using that FullName (which includes > the > > public key) to resolve the assembly using AssemblyResolver. However, > this > > doesn't work properly either, because then the modified assembly gets an > > indirect dependency on a higher version of mscorlib, somehow. Also, this > > seems like a really roundabout way to do this. > > > > -- > > -- > > -- > > 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] <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- -- -- 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]. For more options, visit https://groups.google.com/d/optout.
