Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostSharp and uninitialized objects

Tags:

postsharp

Assumed I have an aspect implementing IInstanceScopedAspect and I have this aspect applied to methods in a type. How can I initialize the aspects when creating the object with FormatterServices.GetUninitializedObject? The constructor is not executed and therefore I get a NullReferenceException when I execute the method where the aspect is applied.

Is there a PostSharp API which can be used to initialize the object's aspects ?

like image 511
Matthias Avatar asked Nov 12 '22 17:11

Matthias


1 Answers

There is a InitializeCurrentAspects method available for exactly this scenario, as documented here; http://doc.sharpcrafters.com/postsharp-2.0/Default.aspx##PostSharp-2.0.chm/html/M_PostSharp_Aspects_AspectUtilities_InitializeCurrentAspects.htm

like image 185
RJ Lohan Avatar answered Jan 01 '23 12:01

RJ Lohan