none
Windows 8: Cannot find 'AsBuffer' extension method. RRS feed

  • Question

  • This is another issue stemming from this earlier thread.

    Now I cannot get at AsBuffer - an extension method.

    This is a Windows 8 .Net 4.5 class library - the same source compiles fine in a Phone 8 and Store app class library.

    In the Phone 8 project (which builds/runs fine), if I click on AsBuffer and use 'Go To Definition', I get this:

    #region Assembly System.Runtime.WindowsRuntime.dll, v4.0.0.0
    // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\System.Runtime.WindowsRuntime.dll
    #endregion
    
    using System;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Security;
    using Windows.Storage.Streams;
    
    namespace System.Runtime.InteropServices.WindowsRuntime
    {
        // Summary:
        //     [SECURITY CRITICAL] Provides extension methods for operating on buffers (Windows.Storage.Streams.IBuffer
        //     interface).
        [SecurityCritical]
        public static class WindowsRuntimeBufferExtensions

    This shows me which assembly and namespace the extension classs resides in - from that project's 'point of view' anyway.

    If I do this again in the Store project (which also builds/runs fine) - I see almost the same:

    #region Assembly System.Runtime.WindowsRuntime.dll, v4.0.0.0
    // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
    #endregion
    
    using System;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Security;
    using Windows.Storage.Streams;
    
    namespace System.Runtime.InteropServices.WindowsRuntime
    {
        // Summary:
        //     [SECURITY CRITICAL] Provides extension methods for operating on Windows Runtime
        //     buffers (Windows.Storage.Streams.IBuffer interface).
        [SecurityCritical]
        public static class WindowsRuntimeBufferExtensions

    So the extensions are in a class in the assembly System.Runtime.WindowsRuntime (although there are physically different assemblies for Phone and Store usage).

    But I cannot add a ref to such an assembly in the ordinary .Net 4.5 class library - yet I have explicitly targeted Windows 8 (in the project file) and have browsed the 'Facade' assemblies folder too.

    This is all extremely confusing and very time consuming - how are we meant to handle this kind of development?

    Am I doing something wrong, is there a bug or oversight in VS 2012? is it possible to use these extensions in a Windows .Net 4.5 class library that targets Windows 8?

    This same project is also failing due to the 'await' keyword, citing:

    'await' requires that the type 'Windows.Foundation.IAsyncAction' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?

    The list of assemblies referenced by this project is:

    Microsoft.CSharp
    System
    System.Core
    System.Data
    System.Data.DataSetExtensions
    System.Runtime
    System.Runtime.InteropServices.WindowsRuntime
    System.Xml
    System.Xml.Linq
    Windows

    (The InteropServices one is the one that defines IBuffer - used by AsBuffer).

    and the using list in the source file is:

    using System;
    using System.Text;
    using System.Runtime.InteropServices.WindowsRuntime;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Windows.Networking.Sockets;
    using Windows.Storage.Streams;

    Just to be clear this same source compiles, builds and runs fine in a Phone 8 class library project and a Store class library project (though the referenced assemblies list differs in each project due to platform differences).

    I guess a 'challenge' here is to create a .Net 4.5 class library project that specifically targets Windows 8 (by editing the project file, see earlier thread mentioned at the start of this post) and invokes AsBuffer on some simple byte[] variable. Anyone who can do that will be proving it is possible and reveal what I need to do...

    Thanks

    Cap'n







    Monday, February 25, 2013 4:13 PM

Answers

  • OK I have an update on this - I managed to 'resolve' the issue.

    I did so after reading this other MSDN thread.

    I manually browsed to the folder:

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319

    and then manually added the ref to System.Runtime.WindowsRuntime.dll

    But is this correct? how are we to know which assemblies can or should be manually added?

    Why does this assembly not appear in automatically when we use Add Reference?

    Is this possibly because I tweaked the project file to specifically target Windows 8?

    Thanks

    Cap'n

    Monday, February 25, 2013 5:11 PM

All replies