Hi again,

After a little testing it seems that this logic write the desired info at 
assembly metadata :

 (replacing the one related with custom attributes of previous code-snipped)

                            ExportedType exportedType = new ExportedType(
                                  typeForwardToReference.Namespace,
                                  typeForwardToReference.Name,
                                  referAssembly.MainModule,
                                  typeForwardToReference.Scope)
                            {
                                Attributes = TypeAttributes.Forwarder
                            };

                            
targetAssembly.MainModule.ExportedTypes.Add(exportedType);
                             //... save assembly, etc....


outputs:

.class extern forwarder System.Web.Mvc.TagBuilder
{
  .assembly extern System.Web.WebPages
}

.class extern forwarder System.Web.Mvc.TagRenderMode
{
  .assembly extern System.Web.WebPages
}

etc.....

*First question* : metadata for forwards seems to be ok,......It is also 
necessary to add any manual-attributes-logic as in first approach  ?

*Second* : Original error message is still there :

*Unable to load type 'System.Web.WebPages.PreApplicationStartCode' of 
assembly  'System, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089'.*

So I guess that now it´s time to focus on PreApplicationStartMethod 
assembly attribute : [assembly: 
PreApplicationStartMethod(typeof(PreApplicationStartCode), "Start")]

At first look we see a clear dependency of System.Web.  Any suggestion 
about how to proceed with it ?


Thanks a lot !!
David



El miércoles, 31 de enero de 2018, 8:42:35 (UTC+1), Molowe escribió:
>
> Hi again,
>
> I have found info about to TypeForwardedToAttribute at 
> module.ExportedTypes ....
>
> As I have commented previously, after strong-name deletion of the friend 
> assembly System.Web.Webpages.dll and re-mapping  reference from 
> System.Web.Mvc.dll, TypeForwardedToAttributes at metadata becomes into:
>
> .class extern forwarder System.Web.Mvc.TagBuilder
> {
>   .assembly extern System
> }
>
> Nevertheless, when I load ExportedTypes, scope property seems to point out 
> to previous version of System.Web.Webpages.dll (preserving PublicKeyToke)
>
> I guess that next step will be delete all this info, and create new 
> exported types.....  Is that correct?
>
> In addition....It´s also needed to create custom 
> TypeForwardedToAttribute´s ?
>
>
> So far, I have used this logic without success :
>
>                 // targetAssembly = [System.Web.Mvc]
>                 AssemblyDefinition referAssembly = 
> AssemblyDefinition.ReadAssembly([System.Web.WebPages.Path]);
>                 foreach (var typeForwardToLiteral in typesToBeForward)
>                 {
>                     var typeForwardToDefinition = 
> referAssembly.MainModule.Types.Where(o => o.Name == 
> typeForwardToLiteral).FirstOrDefault();
>                     var typeForwardToReference = 
> targetAssembly.MainModule.ImportReference(typeForwardToDefinition);
>
>                     MethodReference ctor = 
> targetAssembly.MainModule.ImportReference(typeof(TypeForwardedToAttribute).GetConstructor(new
>  
> Type[] { typeof(System.Type) }));
>                     CustomAttribute forwardAttribute = new 
> CustomAttribute(ctor);
>
>                      forwardAttribute.ConstructorArguments.Add(new 
> CustomAttributeArgument(
>                         
>  targetAssembly.MainModule.ImportReference(typeof(System.Type)),
>                          Type.GetType(typeForwardToReference.FullName)));
>
>
>                       
> targetAssembly.CustomAttributes.Add(forwardAttribute);
>                       etc..
>
>
> this doesn´t produce the desired effect at System.Web.Mvc.dll metadata,
>
> In addition, what is the correct way to proceed with ExportedTypes ?
>
>
> Thanks a lot !
> David
>
>
>
> El martes, 30 de enero de 2018, 12:40:01 (UTC+1), Molowe escribió:
>>
>>
>> Mayor source of PEVerify errors seems owing to TypeForwardedTo attribute. 
>>
>> After strong.name deletion all  externs forwarded to 
>> "System.Web.WebPages" are transformed into forwards to "System" (that is 
>> what ILdasm show us)
>>
>>
>> From
>>
>> .class extern forwarder System.Web.Mvc.TagBuilder
>> {
>>   .assembly extern System.Web.WebPages
>> }
>>
>> to
>>
>> .class extern forwarder System.Web.Mvc.TagBuilder
>> {
>>   .assembly extern System
>> }
>>
>>
>> So far I don´t see this assembly attribute living at 
>> AssemblyDefinition.CustomAttributes.
>>
>> Following syntax doesn´t work
>>
>> var attributes = targetAssembly.CustomAttributes.Where(attr 
>> =>attr.AttributeType.FullName == typeof(TypeForwardedToAttribute).FullName
>>
>> Is there any default cecil syntax for accessing and editing this info?, 
>>
>> In this line...., It will be enough using 
>> assemblyDef.Main.Module.ImportReference(type) ?
>>
>>
>> Many thanks !
>> David
>>
>>
>> El martes, 30 de enero de 2018, 10:17:12 (UTC+1), Molowe escribió:
>>>
>>> Hi Jb,
>>>
>>> So far this is the error we are getting:
>>>
>>> Unable to load type 'System.Web.WebPages.PreApplicationStartCode' of 
>>> assembly  'System, Version=4.0.0.0, Culture=neutral, 
>>> PublicKeyToken=b77a5c561934e089'.
>>>
>>> Info PEVerify over System.Web.Mvc.dll also goes in the same direction, 
>>> it´s seems issue comes from custom attributes for PreApplicationStartMethod 
>>> and TpeForwardedTo 
>>>
>>>
>>> In addition, anytime we need to update a reference assembly for fixing 
>>> custom attributes a new strong-name deletion has to be done for saving it, 
>>> so the initial process starts again for referenced assembly (transitivity 
>>> you metioned)
>>>
>>>
>>>
>>> Thanks
>>> David 
>>>
>>>
>>> El jueves, 25 de enero de 2018, 22:54:16 (UTC+1), Jb Evain escribió:
>>>>
>>>> Removing strong name is usually hard as you have to clean references of 
>>>> the transitive closure of all assemblies that your program uses.
>>>>
>>>> What error are you getting? That will usually tell you where to start 
>>>> looking.
>>>>
>>>> Jb
>>>>
>>>> On Fri, Jan 19, 2018 at 7:43 AM, Molowe <[email protected]> wrote:
>>>>
>>>>> Hi 
>>>>>
>>>>> I have built an Injector framework basis on Cecil. So far, I have no 
>>>>> issues for injecting aspects to custom.Net Assemblies (client code), so 
>>>>> one 
>>>>> of my goals is to take step further and try to inject some logic inside 
>>>>> native .NET Assemblies (in this case I´m instrumenting 
>>>>> System.Web.Mvc.dll). 
>>>>> I´m able to inject required aspects inside it, and delete System.Web.Mvc 
>>>>> strong name and related attributes (creating a new copy) , and update 
>>>>> SampleWeb.dll (MVC web proyect which references System.web.Mvc.dll) 
>>>>> reference for consuming the clean copy of System.Web.Mvc.dll without 
>>>>> strong 
>>>>> name. 
>>>>>
>>>>> In addition I´ve refreshed all SampleWeb.dll references (by directly 
>>>>> importing types inside each one), and also I have updated System.Web.Mvc 
>>>>> references (over new copy). In addition I have updated 
>>>>> "InternalsVisibleTo" 
>>>>> attributes in those assemblies for which System.Web.Mvc.dll depends on 
>>>>> (when needed)
>>>>>
>>>>> So far, I continue exploring posibilities but I´m not able to run 
>>>>> SampleWeb
>>>>>
>>>>> question here : It should be enough using this approach for achieving 
>>>>> this goal?  or I´m missing something
>>>>>
>>>>> thanks in advance !
>>>>>
>>>>> -- 
>>>>> -- 
>>>>> --
>>>>> 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.
>>>>>
>>>>
>>>>

-- 
-- 
--
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.

Reply via email to