none
Cannot add ref to Windows.Networking.DLL RRS feed

  • Question

  • I'm trying to create a .Net 4.5 class library in C# with VS 2012.

    I want to use the class DatagramSocket which is in the namespace Windows.Networking.Sockets.

    But when I try to add a reference to the required assembly - Windows.Networking.DLL - I cannot do so.

    It does not appear in the list of available assemblies.

    If I right click on the unresolved class name DatagramSocket and choose 'Resolve' the context menu does know that the class is in the namespace Windows.Networking.Sockets but even after it adds the necessary 'using' directive, the build fails because it says the type/namespace 'Windows' cannot be found.

    I'm either being dumb or there's something wrong here !

    Thanks

    Cap'n


    Saturday, February 23, 2013 9:47 PM

Answers

All replies

  • I see it in the Windows reference in VS 2012 for Win 8 Express... Did you create it as a win8 for store apps class library?

    Here is an example you can experiment.

    http://code.msdn.microsoft.com/windowsapps/DatagramSocket-sample-76a7d82b

    Sunday, February 24, 2013 12:56 PM
    Moderator
  • I see it in the Windows reference in VS 2012 for Win 8 Express... Did you create it as a win8 for store apps class library?

    Here is an example you can experiment.

    http://code.msdn.microsoft.com/windowsapps/DatagramSocket-sample-76a7d82b

    I have been able to use DatagramSocket fine on both a Windows Phone 8 app and a Store app.

    But I cant get at the class from an ordinary (not Store or Phone) .Net 4.5 class library project.

    The doc (here) says at the end, that it can be used for Store and Desktop apps on Win8 and Server 2012.

    Most puzzling.

    Cap'n

    Sunday, February 24, 2013 4:58 PM
  • Please check this article:

    Managed desktop apps and Windows Runtime (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/jj856306.aspx

    • Marked as answer by Captain Kernel Monday, February 25, 2013 2:56 PM
    Sunday, February 24, 2013 5:35 PM
  • Classic windows apps use System.Net.Sockets.Socket class both for streams and datagrams.

    If you want to use a Windows8-specific classes in your library, you should declare your project as targeted for Windows 8 by manually editing your csproj file:

      <PropertyGroup>
        <TargetPlatformVersion>8.0</TargetPlatformVersion>
      </PropertyGroup>

    After that your dll would be inaccessible on earlier Windows versions.

    • Proposed as answer by Rageko Wednesday, April 15, 2015 9:02 PM
    Monday, February 25, 2013 4:11 AM
  • Classic windows apps use System.Net.Sockets.Socket class both for streams and datagrams.

    If you want to use a Windows8-specific classes in your library, you should declare your project as targeted for Windows 8 by manually editing your csproj file:

      <PropertyGroup>
        <TargetPlatformVersion>8.0</TargetPlatformVersion>
      </PropertyGroup>

    After that your dll would be inaccessible on earlier Windows versions.

    Well that did resolve the DatagramSocket issue but now System.IDisposable is a problem.

    VS 2012 says I need to now add a ref to System.Runtime - but again I cannot see that listed as an option when I try to add a reference.

    This is very time consuming and could be handled better by Visual Studio.

    FYI - I have a single solution that has a Phone 8 class library, a Store class library and an 'ordinary' .Net 4.5 class library (whose project file I have now tweaked as you advised).

    Each project has links to a common set of source files, this offers greater flexibility than using a 'portable' class library which I have found is rather limiting.

    Thanks for your help though!

    Cap'n





    Monday, February 25, 2013 2:02 PM
  • Please check this article:

    Managed desktop apps and Windows Runtime (Windows)

    http://msdn.microsoft.com/en-us/library/windows/apps/jj856306.aspx

    Thanks - that helped too - allowed me to add the System.Runtime assembly, but there are still problems now - new ones....

    For example I am seeing this reported now:

    Property, indexer, or event 'Windows.Networking.Sockets.DatagramSocket.MessageReceived' is not supported by the language; try directly calling accessor methods 'Windows.Networking.Sockets.DatagramSocket.add_MessageReceived Windows.Foundation.TypedEventHandler<Windows.Networking.Sockets.DatagramSocket,Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs>)' or 'Windows.Networking.Sockets.DatagramSocket.remove_MessageReceived(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken)'

    This is where I add (i.e. += ) an event handler method to that event - the same code compiles and runs fine - in the Phone 8 and Store projects.

    This is also reported

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

    the sources DOES have a using System; directive too.

    Cap'n





    Monday, February 25, 2013 2:56 PM
  • Hi Captain,

    Nice to see you.

    "System.IDisposable" is a interface from System namespace which is in "mscorlib.dll". It should be already referenced.

    About the System.runtime dll, please check this path:

    AddReference > Browse > C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Runtime.dll

    And more is here: http://www.codeproject.com/Articles/457335/How-to-call-WinRT-APIs-from-NET-desktop-apps 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 25, 2013 3:14 PM
    Moderator
  • Hi Captain,

    Nice to see you.

    "System.IDisposable" is a interface from System namespace which is in "mscorlib.dll". It should be already referenced.

    About the System.runtime dll, please check this path:

    AddReference > Browse > C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\System.Runtime.dll

    And more is here: http://www.codeproject.com/Articles/457335/How-to-call-WinRT-APIs-from-NET-desktop-apps 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Yep I did all that - but this is very bewildering. It seems that one must use trial-and-error to get this to work.

    The error messages are very bewildering and it is guesswork to find out which assemblies one needs to add.

    I've worked with .Net for years and seen pretty much everything when it comes to fixing issues with namespaces and assemblies - this situation is different and pretty poor I think.

    See my two recent replies above for more info about what I'm now seeing.

    I just added a ref to another of the 'facade' assemblies (System.Runtime.InteropServices.WindowsRuntime) and as I say, this was little more than an educated guess.

    This is no way to create high quality software.

    Thanks

    Cap'n


    Monday, February 25, 2013 3:21 PM