locked
C# Component with javascript error. RRS feed

  • Question

  • (I posted this question to the C#/VB forum. Just realized its probably in the wrong spot. http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/5bb97688-2887-43ad-9ba3-af84ef2dd7f9).

    I am creating an api wrapper in C# to be called from my javascript.

    Whenever I return a class that I defined, in IAsyncOperation<T> I get the javascript error: 'Unable to get value of the property 'then': object is null or undefined'

    If I cast my object (called CustomObject) to an object type, it works, however when casting to an object type I can no longer access a complex member variable like a list which exists in CustomObject. 

    Is this a known issue?

     

    Monday, December 19, 2011 7:57 PM

Answers

All replies

  • I created a

     

    IAsyncOperation<CustomObject> Get(string url)

     

    it waits on an api call that returns a CustomObject. This gives me an error: 'Unable to get value of the property 'then': object is null or undefined'

    If I cast the CustomObject to an Object the call works. However, My Custom object looks like 

     

    [DataContract]

     public sealed class CustomObject{

            public  CustomObject ()

            {

            }

            [DataMember]

            public int ResultCount { get; set; }

            [DataMember]

            public IList<OtherObject> Results { get; set; }

        }

     

    and the CustomObject is not properly cast, meaning the IList<OtherObject> is not properly cast.

     

    Any ideas?

    • Merged by Jie Bao Tuesday, December 20, 2011 7:57 AM duplicate
    Monday, December 19, 2011 5:11 PM
  • it waits on an api call that returns a CustomObject. This gives me an error: 'Unable to get value of the property 'then': object is null or undefined'

    If I cast the CustomObject to an Object the call works. However, My Custom object looks like

    very-very strange word "then" in your error details.
    Kind regards, HeToC. http://www.linkedin.com/in/hetoc
    Monday, December 19, 2011 5:57 PM
  • To Clarify, that is the javascript error.

     

    If I try to debug the managed code I get this error:

     

    Managed Debugging Assistant 'InvalidMemberDeclaration' has detected a problem in 'C:\Windows\System32\WWAHost.exe'.

    Additional Information: The following error occurred while determining how to marshal the parameters of member 'Get' of type 'TestAPI.IAsyncMethodsClass': System.BadImageFormatException: Unable to compute GUID for type 'Windows.Foundation.IAsyncOperation`1[TestAPI.Models.CustomObject]' because the instantiation contains types that are not supported by Windows Runtime. This is most likely due to an incompatible MarshalAs attribute on one of the parameters. 

    Monday, December 19, 2011 6:09 PM
  • To put this more generically,

    Whenever I return a user defined WinRT object in IAsyncOperation<T>, like CustomObject (defined above) I get an error. 

    Is this a known issue?

    Monday, December 19, 2011 6:34 PM
  • I moved this to the Javascript/html 5 forum. I just realized this question is probably in the wrong forum.  http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/51914531-22bf-4c61-aa02-80c1fb37cdb6
    Monday, December 19, 2011 7:58 PM
    • Marked as answer by Nik2000 Monday, December 19, 2011 8:56 PM
    Monday, December 19, 2011 8:33 PM
    Moderator