Cannot reference field of type defined in Universal Windows assembly

avatar's Avatar

avatar

24 May, 2017 09:19 PM

...where the class the field is within has an aspect on it. The code in question is as follows:

    using Windows.Devices.Bluetooth;

    using PostSharp.Patterns.Model ;
    using PostSharp.Patterns.Threading ;

    [Synchronized]
    [Aggregatable]
    internal sealed class Win10NativeAdapter : IBluetoothAdapter
    {
        private BluetoothAdapter actualAdapter ;

        ...
    }

Which on compilation generates the error:

    Error PS0125: An unexpected exception occurred when executing user code: System.ArgumentOutOfRangeException: Cannot find the declaration of Windows.Devices.Bluetooth.BluetoothAdapter actualAdapter.
Parameter name: target
   at PostSharp.Sdk.Extensibility.Tasks.AnnotationRepositoryTask.^+GBuIgPsuWT3(Object _0, ReflectionSearchOptions _1)
   at PostSharp.Reflection.ReflectionSearch.GetCustomAttributesOnTarget(Object target, ReflectionSearchOptions options)
   at PostSharp.Reflection.ReflectionSearch.GetCustomAttributesOnTarget[T](Object target, ReflectionSearchOptions options)
   at PostSharp.Patterns.Model.AggregatableAttribute.CompileTimeValidate(Type type)
   at PostSharp.Aspects.TypeLevelAspect.CompileTimeValidate(Object target)
   at PostSharp.Sdk.AspectWeaver.AspectWeaverInstance.^pCdttYEs.^Q7McNsOl()
   at PostSharp.Sdk.Utilities.ExceptionHelper.ExecuteUserCode[T](MessageLocation messageLocation, Func`1 userCode, Type[] acceptableExceptions). (1, 1)

Is there a way around/fix for this? I'm currently using 5.0.24-preview.

Regards,

Alistair

  1. Support Staff 1 Posted by PostSharp Techn... on 25 May, 2017 01:25 PM

    PostSharp Technologies's Avatar

    Hello,

    UWP is not currently supported. I would advise against using PostSharp in such project as you may run into problems (i.e. with .NET Native).

    Best regards,
    Daniel

  2. 2 Posted by avatar on 25 May, 2017 01:48 PM

    avatar's Avatar

    Argh! What I have, unfortunately, is an existing .NET/Win32 desktop project - that makes extensive use of PostSharp - from which I need to reference a UWP assembly in this single class...

    Understanding that it's not supported, could you advise me if creating a separate (non-PostSharp-using) .NET assembly to wrap the UWP references entirely, and then calling into that from the main project would be a viable workaround?

    Thanks,

    Alistair

  3. Support Staff 3 Posted by PostSharp Techn... on 26 May, 2017 05:44 AM

    PostSharp Technologies's Avatar

    Hello,

    yes, that should work as long as you don't execute the code containing references to UWP types in build time.

    It's even possible that there will be no problem if you separate UWP-using types and PostSharp-enhanced types within the same assembly. That means if you encapsulate private BluetoothAdapter actualAdapter into a different type, PostSharp may still be able to process the assembly. It needs a bit of experimentation.

    Best regards,
    Daniel

  4. 4 Posted by avatar on 18 Jun, 2017 10:55 AM

    avatar's Avatar

    Thank you, that helps a lot.

    Alistair

  5. avatar closed this discussion on 18 Jun, 2017 11:00 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac