Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i use in assembly level? #83

Closed
drony opened this issue Feb 7, 2019 · 15 comments
Closed

Can i use in assembly level? #83

drony opened this issue Feb 7, 2019 · 15 comments
Assignees
Labels

Comments

@drony
Copy link

drony commented Feb 7, 2019

when i tried i got this error

aspect file

[Aspect(Scope.Global)]
[Injection(typeof(LoggingAspect))]
[AttributeUsage(AttributeTargets.All, Inherited = false)]
public class LoggingAspect : Attribute

in assembly

[assembly: LoggingAspect()]

4>C:\Users\xxxx\source\Workspaces\xxx\xxx\Abstract\Device.cs(14,21,14,23): warning CS0169: The field 'Device.v2' is never used
4>  AspectInjector: Started for TPS.Hardware.dll
4>  AspectInjector: Assembly has been read.
4>  AspectInjector: Found 0 aspects
4>  AspectInjector: Found 1218 injections
4>  AspectInjector: Processing injections...
4>  AspectInjector: Executing AdviceInlineWeaver...
4>  AspectInjector: Executing AdviceStateMachineWeaver...
4>  AspectInjector: Executing AdviceAroundWeaver...
4>AspectInjector : error AI_ERR0: Processing failure: System.NullReferenceException: Object reference not set to an instance of an object.
4>     at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.MoveBody(MethodDefinition from, MethodDefinition to)
4>     at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.WrapEntryPoint(MethodDefinition unwrapper)
4>     at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.GetOrCreateUnwrapper()
4>     at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.GetNextWrapper()
4>     at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.Execute()
4>     at AspectInjector.Core.Processor.ProcessAssembly(AssemblyDefinition assembly, Boolean optimize)
4>     at AspectInjector.Core.Processor.Process(String assemblyFile, IAssemblyResolver resolver, Boolean optimize)
4>     at AspectInjector.Commands.ProcessCommand.Execute(IReadOnlyList`1 args). Please submit an issue to https://github.com/pamidur/aspect-injector
4>AspectInjector : error AI_FAIL: Aspect Injector processing has failed. See other errors.
5>------ Build started: Project:xxxxx.Test.App, Configuration: Debug x86 ------
@drony drony changed the title Can i use assembly level? Can i use in assembly level? Feb 7, 2019
@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

Hi,
I could not reproduce this case. I suspect aspectInjector tries to wrap around method which is not a method somehow (idk, maybe something from COM or p/invoke).
Could you please provide more code so we can see what exactly in the Assembly you're injecting to?

@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

Ok, i found a problem. This is regression issue with abstract and external methods which was already fixed before. I'll fix it soon

@pamidur pamidur self-assigned this Feb 7, 2019
@pamidur pamidur added the bug label Feb 7, 2019
@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

fixed in 2.0.3

@pamidur pamidur closed this as completed Feb 7, 2019
@drony
Copy link
Author

drony commented Feb 7, 2019

I've just updated. but i think there is a problem with static Main function

public object HandleMethod(
[Argument(Source.Instance)] object instance,
[Argument(Source.Name)] string name,
[Argument(Source.Arguments)] object[] arguments,
[Argument(Source.Target)] Func<object[], object> method)
{

instance is null and i handle instance this time application exit immediately

@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

This is by design.
Static methods (like Main() ) don't have this and you'll receive [Argument(Source.Instance)] object instance = null.

You have to check if instance is null and the process it correctly. Btw you can use [Argument(Source.Type)] this is always not-null

@drony
Copy link
Author

drony commented Feb 7, 2019

thanks but this is a new errors

6> AspectInjector: Started forxxx.dll
6> AspectInjector: Assembly has been read.
6> AspectInjector: Found 0 aspects
6> AspectInjector: Found 958 injections
6> AspectInjector: Processing injections...
6> AspectInjector: Executing AdviceInlineWeaver...
6> AspectInjector: Executing AdviceStateMachineWeaver...
6> AspectInjector: Executing AdviceAroundWeaver...
6>AspectInjector : error AI_ERR0: Processing failure: System.NotSupportedException: Specified method is not supported.
6> at AspectInjector.Core.Models.PointCut.PickLoadInstruction(TypeReference elemType)
6> at AspectInjector.Core.Models.PointCut.Cast(TypeReference typeOnStack, TypeReference expectedType)
6> at AspectInjector.Core.Fluent.Arrays.SetByIndex(PointCut pc, TypeReference elementType, Int32 index, Action1 value) 6> at AspectInjector.Core.Fluent.Arrays.CreateArray(PointCut pc, TypeReference elementType, Action1[] elements)
6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceWeaveProcessBase1.LoadArgumentsArgument(PointCut pc, AdviceArgument parameter) 6> at AspectInjector.Core.Models.PointCut.Store(VariableDefinition variable, Action1 val)
6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.<>c__DisplayClass11_0.b__0(PointCut e)
6> at AspectInjector.Core.Fluent.MethodEditor.Instead(Action1 action) 6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.WrapEntryPoint(MethodDefinition unwrapper) 6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.GetOrCreateUnwrapper() 6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.GetNextWrapper() 6> at AspectInjector.Core.Advice.Weavers.Processes.AdviceAroundProcess.Execute() 6> at AspectInjector.Core.Processor.ProcessAssembly(AssemblyDefinition assembly, Boolean optimize) 6> at AspectInjector.Core.Processor.Process(String assemblyFile, IAssemblyResolver resolver, Boolean optimize) 6> at AspectInjector.Commands.ProcessCommand.Execute(IReadOnlyList1 args). Please submit an issue to https://github.com/pamidur/aspect-injector
6>AspectInjector : error AI_FAIL: Aspect Injector processing has failed. See other errors.
7>------ Build started: Project:xxx, Configuration: Debug Any CPU ------
7> All packages listed in packages.config are already installed.

@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

Do you use unsafe code?
It seems there is some unusual method argument is your code.

@drony
Copy link
Author

drony commented Feb 7, 2019

yes unsafe code available

@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

Can I have any sample on there you pass pointers into method as a parameters?

@drony
Copy link
Author

drony commented Feb 7, 2019

actually this is a very very large library. i prepare lightweight sample soon as possible.
thanks for your help

@drony
Copy link
Author

drony commented Feb 7, 2019

I've recompiled this line from source code:

AspectInjector.Core>Fluent>PointCut.cs

private Instruction PickStoreInstruction(TypeReference parameterType)
{
var elemType = ((ByReferenceType)parameterType).ElementType;

        switch (elemType.MetadataType)
        {
            case MetadataType.Class: return CreateInstruction(OpCodes.Stind_Ref);
            case MetadataType.Object: return CreateInstruction(OpCodes.Stind_Ref);
            case MetadataType.MVar: return CreateInstruction(OpCodes.Stobj, elemType);
            case MetadataType.Var: return CreateInstruction(OpCodes.Stobj, elemType);
            case MetadataType.Double: return CreateInstruction(OpCodes.Stind_R8);
            case MetadataType.Single: return CreateInstruction(OpCodes.Stind_R4);
            case MetadataType.Int64: return CreateInstruction(OpCodes.Stind_I8);
            case MetadataType.UInt64: return CreateInstruction(OpCodes.Stind_I8);
            case MetadataType.Int32: return CreateInstruction(OpCodes.Stind_I4);
            case MetadataType.UInt32: return CreateInstruction(OpCodes.Stind_I4);
            case MetadataType.Int16: return CreateInstruction(OpCodes.Stind_I2);
            case MetadataType.UInt16: return CreateInstruction(OpCodes.Stind_I2);
            case MetadataType.Byte: return CreateInstruction(OpCodes.Stind_I1);
            case MetadataType.SByte: return CreateInstruction(OpCodes.Stind_I1);
            case MetadataType.Boolean: return CreateInstruction(OpCodes.Stind_I1);
            case MetadataType.Char: return CreateInstruction(OpCodes.Stind_I2);
            case MetadataType.UIntPtr: return CreateInstruction(OpCodes.Stind_I);
            case MetadataType.IntPtr: return CreateInstruction(OpCodes.Stind_I);
            case MetadataType.String: return CreateInstruction(OpCodes.Stind_I);
        }

        **throw new NotSupportedException(elemType.MetadataType.ToString());**
    }

here is the missing type: -> String

5> All packages listed in packages.config are already installed.
5> AspectInjector: Started for xxx.dll
5> AspectInjector: Assembly has been read.
5> AspectInjector: Found 0 aspects
5> AspectInjector: Found 42 injections
5> AspectInjector: Processing injections...
5> AspectInjector: Executing AdviceInlineWeaver...
5> AspectInjector: Executing AdviceStateMachineWeaver...
5> AspectInjector: Executing AdviceAroundWeaver...
5>AspectInjector : error AI_ERR0: Processing failure: System.NotSupportedException: String

@drony
Copy link
Author

drony commented Feb 7, 2019

and it think add this line should be fix:

case MetadataType.String: return CreateInstruction(OpCodes.Ldind_Ref);

@drony
Copy link
Author

drony commented Feb 7, 2019

for my project:

MetadataType.ValueType
MetadataType.GenericInstance
MetadataType.String
MetadataType.Array

missing in pointcut.cs in 2 locations

@pamidur
Copy link
Owner

pamidur commented Feb 7, 2019

have a try 2.0.5

@drony
Copy link
Author

drony commented Feb 8, 2019

thanks it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants