locked
Proximity API PublishBinaryMessage() always runs into ArgumentException: "Value does not fall within the expected range."

    Question

  • Hello there! I have been trying to use Proximity APIs on Windows 8.1 to read and write to NFC tag. I can read the tag fine, but when it comes to writing using PublishBinaryMessage, I run into ArgumentException saying "Value does not fall within the expected range." The call that results in this exception is on line 4: 

    var dataWriter = new Windows.Storage.Streams.DataWriter();
    dataWriter.WriteString("Hello!!");
    var ibuff = dataWriter.DetachBuffer();
    PublishedId = proximityDevice.PublishBinaryMessage("NDEF", ibuff, DoneWriting);

    I saw that the message-type in the first argument is restricted to some values, and NDEF is one of them, so I used it here. Do I need to format the second argument to NDEF format before I use it? If so then how to do it? If I used another API PublishMessage as: 

    proximityDevice.PublishMessage("Windows.Sample", "Hello!!", DoneWriting);

    The callback function DoneWriting never gets called. I checked that the tag is writable using Android app "NFC Tools". Any ideas of what I am missing here?

    Thanks for your time!

    Friday, March 13, 2015 11:38 PM

Answers

  • Hi MSRockOn,

    >>I run into ArgumentException saying "Value does not fall within the expected range." The call that results in this exception is on line 4

    This issue maybe caused by incorrect formatted message for NDEF MessageType in ProximityDevice.PublishBinaryMessage method.

    Quote from: https://msdn.microsoft.com/library/windows/apps/hh701129.aspx

    NDEF

    The message contents are properly formatted NDEF records. The underlying type of the content for a publication using NDEF as the message type is contained in the NDEF records. A subscription for the NDEF type subscribes to all NDEF formatted messages.

    Proximity API does not give tools to manipulate directly NDEF messages. To manipulate raw NDEF messages you can use NDEF Library for Proximity APIs (NFC), please refer to this document for details: http://developer.nokia.com/community/wiki/Use_NFC_tags_with_Windows_Phone_8


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 5:44 AM
    Moderator

All replies

  • Hi MSRockOn,

    >>I run into ArgumentException saying "Value does not fall within the expected range." The call that results in this exception is on line 4

    This issue maybe caused by incorrect formatted message for NDEF MessageType in ProximityDevice.PublishBinaryMessage method.

    Quote from: https://msdn.microsoft.com/library/windows/apps/hh701129.aspx

    NDEF

    The message contents are properly formatted NDEF records. The underlying type of the content for a publication using NDEF as the message type is contained in the NDEF records. A subscription for the NDEF type subscribes to all NDEF formatted messages.

    Proximity API does not give tools to manipulate directly NDEF messages. To manipulate raw NDEF messages you can use NDEF Library for Proximity APIs (NFC), please refer to this document for details: http://developer.nokia.com/community/wiki/Use_NFC_tags_with_Windows_Phone_8


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 5:44 AM
    Moderator
  • Thanks Franklin for your response. I got a hold of an open source library to do the formatting part, from https://github.com/andijakl/ndef-nfc. However, on trying to use ToArray() method on IBuffer, I now run into
    error CS0012: The type 'Windows.Storage.Streams.IBuffer' is defined in an assembly that is not referenced

    in spite of having referenced "System.Runtime.InteropServices.WindowsRuntime". The error further goes to say I should add reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. I am creating a console application, is that the reason of running into these problems? Are these APIs only meant for WinRT apps?
    Tuesday, March 17, 2015 4:45 PM
  • Thanks Franklin for your response. I got a hold of an open source library to do the formatting part, from https://github.com/andijakl/ndef-nfc. However, on trying to use ToArray() method on IBuffer, I now run into
    error CS0012: The type 'Windows.Storage.Streams.IBuffer' is defined in an assembly that is not referenced

    in spite of having referenced "System.Runtime.InteropServices.WindowsRuntime". The error further goes to say I should add reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. I am creating a console application, is that the reason of running into these problems? Are these APIs only meant for WinRT apps?

    Hi MSRockOn,

    >> I am creating a console application, is that the reason of running into these problems? Are these APIs only meant for WinRT apps?

    Yes, it means you can't use these APIs in desktop project.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 18, 2015 7:29 AM
    Moderator