Hey JB ,

any clues/hints on the above? :)

csk

On May 30, 8:40 am, srcKode <[email protected]> wrote:
> hi jb,
>
> this is the code that i wrote to inject custom attributes from an
> existing type to a target type ... works on most of the attributes but
> for the ClassInterfaceAttribute, am also having issues with the
> MarshalAsAttribute too; unable to set the MarshalSpec
>
>   foreach (CustomAttribute attribute in sourceType.CustomAttributes)
>                 {
>                     IList ctorParams =
> attribute.ConstructorParameters;
>                     MethodReference constructor =
> targetAssembly.MainModule.Import(attribute.Constructor);
>
>                     CustomAttribute attr = new
> CustomAttribute(constructor);
>                     bool resolved = attr.Resolve();
>
>                     for (int prmCount = 0; prmCount <=
> ctorParams.Count - 1; prmCount++)
>
> attr.ConstructorParameters.Add(ctorParams[prmCount]);
>
>                     foreach (DictionaryEntry prop in
> attribute.Properties)
>                     {
>                         attr.Properties.Add(prop.Key, prop.Value);
>                         attr.SetPropertyType(prop.Key.ToString(),
> targetAssembly.MainModule.Import(prop.Value.GetType()));
>                     }
>
>                     foreach (DictionaryEntry field in
> attribute.Fields)
>                     {
>                         attr.Fields.Add(field.Key, field.Value);
>                         attr.SetFieldType(field.Key.ToString(),
> targetAssembly.MainModule.Import(field.Value.GetType()));
>                     }
>
>                     destType.CustomAttributes.Add(attr);
>
>                 }
>
> csk ...
>
> On May 27, 4:34 pm, Jb Evain <[email protected]> wrote:
>
> > Granted that you're not showing any code, it's hard to tell you what
> > you're doing wrong :)
>
> > On Fri, May 27, 2011 at 1:06 PM, srcKode <[email protected]> wrote:
> > > if i just had to patch the source,what classes do you suggest I need
> > > to upgrade.
> > > Migrating to the new version may require lot of re-work for me.
>
> > > On May 27, 3:08 pm, Jb Evain <[email protected]> wrote:
> > >> Hi,
>
> > >> You should update to Cecil 0.9x from github.
>
> > >> On Fri, May 27, 2011 at 11:55 AM, srcKode <[email protected]> 
> > >> wrote:
> > >> > oops sorry,this error was when i tried to save the assembly after a
> > >> > Type was imported from other assembly.
>
> > >> > On May 27, 2:33 pm, srcKode <[email protected]> wrote:
> > >> >> Hi,
>
> > >> >> I am having issues when I try to import a class that is decorated with
> > >> >> the [ClassInterface] attribute;
>
> > >> >> below is the stack trace :
>
> > >> >> StackTrace  "   at System.Collections.ArrayList.get_Item(Int32 
> > >> >> index)\r
> > >> >> \n
> > >> >>                 at 
> > >> >> Mono.Cecil.ReflectionWriter.GetCustomAttributeSig(CustomAttribute
> > >> >> ca) in ..\\ReflectionWriter.cs:line 1435\r\n
> > >> >>                 at
> > >> >> Mono.Cecil.ReflectionWriter.VisitCustomAttributeCollection(CustomAttributeCollection
> > >> >> customAttrs) in ..\\ReflectionWriter.cs:line 666\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.CustomAttributeCollection.Accept(IReflectionVisitor
> > >> >> visitor) in ..\\CustomAttributeCollection.cs:line 90\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.TypeDefinition.Accept(IReflectionVisitor visitor) in ..
> > >> >> \\TypeDefinition.cs:line 558\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.ReflectionWriter.CompleteTypeDefinitions() in ..\
> > >> >> \ReflectionWriter.cs:line 357\r\n
> > >> >>                 at
> > >> >> Mono.Cecil.StructureWriter.TerminateAssemblyDefinition(AssemblyDefinition
> > >> >> asm) in ..\\StructureWriter.cs:line 242\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.AssemblyDefinition.Accept(IReflectionStructureVisitor
> > >> >> visitor) in ..\\AssemblyDefinition.cs:line 161\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.AssemblyFactory.WriteAssembly(AssemblyDefinition asm,
> > >> >> BinaryWriter bw) in ..\\AssemblyFactory.cs:line 133\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.AssemblyFactory.SaveAssembly(AssemblyDefinition asm,
> > >> >> Stream stream) in ..\\AssemblyFactory.cs:line 157\r\n
> > >> >>                 at 
> > >> >> Mono.Cecil.AssemblyFactory.SaveAssembly(AssemblyDefinition asm,
> > >> >> String file) in ..\\AssemblyFactory.cs:line 141\r\n
> > >> >>                 at .TypeImporter.ImportType in 
> > >> >> ..\\TypeImporter.cs:line 1248"      string
>
> > >> >> Is it something that got to do with the Type Library Exporter ;
> > >> >> with any other custom attribute it works fine.
>
> > >> > --
> > >> > --
> > >> > mono-cecil
>
> > > --
> > > --
> > > mono-cecil

-- 
--
mono-cecil

Reply via email to