|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
Hello
I have this error when I mix several aspect : "AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I am currently mixing 3 aspects. When I comment one of those it works correctly.
First I will inject an interface on an object :
public interface IObservable { }
[Serializable] internal class ObservableImplementation : IObservable { }
[Serializable] internal class ObservableAttribute : CompositionAspect { public override Type GetPublicInterface(Type containerType) { return typeof(IObservable); }
public override object CreateImplementationObject(InstanceBoundLaosEventArgs eventArgs) { return new ObservableImplementation(); }
public override CompositionAspectOptions GetOptions() { CompositionAspectOptions options = base.GetOptions(); options |= CompositionAspectOptions.GenerateImplementationAccessor; return options; } }
I also want to inject some code in my property setters so I have declared the following aspect :
[Serializable] [MulticastAttributeUsage(MulticastTargets.Method, AllowExternalAssemblies = true, Inheritance = MulticastInheritance.Multicast)] internal partial class TrackPropertyChangesAttribute : OnMethodBoundaryAspect { public override bool CompileTimeValidate(MethodBase method) { return method.Name.StartsWith("set_"); } }
And I set these aspects to my object :
[Observable] [Serializable] [TrackPropertyChanges] public abstract class ObjetObservable { }
Finally I decalre another aspect that will inject a new field in my classes (but that does nothing for now):
[Serializable] [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] [MulticastAttributeUsage(MulticastTargets.Field)] [RequirePostSharp("InjectFieldLoadedPlugin", "InjectFieldLoadedTask")] public class LazyLoadingAttribute : CompoundAspect { public override void ProvideAspects(object element, LaosReflectionAspectCollection collection) { collection.AddAspect(element, new ImplementInjectFieldAspect()); } }
<?xml version="1.0" encoding="utf-8" ?>
<PlugIn xmlns="http://schemas.postsharp.org/1.0/configuration"> <SearchPath Directory="bin/{$Configuration}"/> <TaskType Name="InjectFieldLoadedTask" Implementation="Framework.Data.DataAccessLayer.Aspects.LazyLoading.InjectFieldLoadedTask, ConsoleApplication1" /> </PlugIn>
[Serializable] internal class ImplementInjectFieldAspect : ILaosFieldLevelAspect { void ILaosFieldLevelAspect.RuntimeInitialize(FieldInfo field) { } }
internal class InjectFieldLoadedTask : Task, ILaosAspectWeaverFactory { LaosAspectWeaver ILaosAspectWeaverFactory.CreateAspectWeaver(AspectTargetPair aspectSemantic) { if ( aspectSemantic.IsDerivedFrom(typeof(ImplementInjectFieldAspect))) return new InjectFieldLoadedWeaver();
return null; } }
internal class InjectFieldLoadedWeaver : FieldLevelAspectWeaver { public InjectFieldLoadedWeaver() : base(null) { }
public override void Implement() { } }
Note that I want my attribute to be a Compound because I will in the future add another aspect in it.
Note also that when I was having all my "code generation" code in my aspects, I could see that my classes where correcty processed and updated.
Finally I add a versy simple code :
public class UnitTest1 { static int Main(string[] args) { var objet = new MonDossierAvecUnPret_Observable(); objet.AutrePropriete = 15;
return 0; }
public class MonDossierAvecUnPret_Observable : ObjetObservable { public int AutrePropriete { get; set; }
[LazyLoading] public MonPretObservable Pret; } public class MonPretObservable : ObjetObservable { }
}
And I get the exception when I run it on my constructor. The exception comes from the InitializeAspect method. In my production code, it was coming from <>AspectsImplementationDetails_1..cctor.
Do you have any idea of what's happening ?
For info, I was using the 1.5.6.690 but I have the same behavior with 1.5.6.761
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
|
What is the full exception stack?
|
|
|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
Ah it was at runtime, not build time.
Try to attach a debugger and catch any exception to see what happens.
-g
|
|
|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
Yes sorry, at runtime. I cannot get any error.
In VS, I need to go in assembler code to see where it fails and I cannot get a more precise error.
I have tried to use Deblector to debug in the reflector but I'm not so used to this tool and I have no more precised error.
I continue to investigate
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
|
Yes, but if you can break into the debugger, you can see the stack.
|
|
|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
Not really no..? The only thing I can get in my code is "{"The type initializer for '<>AspectsImplementationDetails_1' threw an exception."}" when calling one of my aspected property.
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
|
So I don't know. You can submit a repro to the issue tracker and i'll have a look.
|
|
|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
OK I have attached the solution. <!-- m --><a class="postlink" href="http://www.postsharp.org/tracker/view.php?id=424">http://www.postsharp.org/tracker/view.php?id=424</a><!-- m -->
|
|
|
|
|
Pierre-Emmanuel Dautreppe
Community Member
|
|
Hello Gaël,
Have you been able to have a look to this problem ?
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
|