Now let's go to the third question.

1
2
3
4
5
6
7
8
9
   [JavaScript]
    public class Base
    {
        public int i = 1;
        public float[] Copies { get; set; } = { };
    }

    [JavaScript, Serializable]
    public class Descendant : Base  {  }

If we only remove SerializableAttribute from the Base class the result will look like the inheritance weren't there at all:

1
Object {  }

But the documentation of the SerializableAttribute says:

The common language runtime throws SerializationException if any type in the graph of objects being serialized does not have the SerializableAttribute attribute applied.

So the CLR makes the developer confident about following: If an object has the SerializableAttribute then it either will be fully serializable or will throw an exception. But WebSharper makes it possible to serialize partally without a notice for developer or direct command from him like NonSerialized.

Will this issue be resolved ?

By on 6/28/2018 3:44 AM ()

Hello, I have created issue #975 for this, will be resolved in next release.

By on 7/2/2018 6:05 AM ()

The next question. Now the code is changed a bit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    [JavaScript, Serializable]
    public class Base
    {
        public int i = 1;
        public float[] Copies { get; set; } = { };
    }

    [JavaScript, Serializable]
    public class Descendant : Base  {  }


    public static class Remoting
    {
        ...
        [Remote]
        public static Task<Descendant> GetObject3(string input)
        {
            var obj = new Descendant();
            return Task.FromResult(obj);
        }
    }

    [JavaScript]
    public static class Client
    {
        ...
        static public void Test()
        {
            Remoting.GetObject3("input").ContinueWith(t => {
                WebSharper.JavaScript.Console.Log(t.Result);
                foreach (var f in t.Result.Copies)
                    WebSharper.JavaScript.Console.Log(f);
                WebSharper.JavaScript.Console.Log("after loop");
            });
        }
    }

So this code writes to console:

1
Object { i: 1 }

instead of expected:

1
2
Object { i: 1, "$Copies": [] }
after loop

Internally, absence of property value results in exception of taking enumerator of null. So the code after loop is not executing. Is it an issue to create?

By on 6/23/2018 6:34 AM ()

Fix is now available in WebSharper 4.3.0

By on 6/26/2018 10:31 AM ()

Thank you very much for the report and detailed example!

This is indeed a bug in RPC result serialization, a fix will be coming soon. I have created ticket https://github.com/dotnet-websharper/core/issues/969

By on 6/26/2018 4:56 AM ()

Hi!

A task for a remote call cannot complete immediately (even if it is defined on the server-side with Task.FromResult, WebSharper inserts the remoting mechanism on both sides), so you must schedule a continuation instead of taking Result immediately:

1
2
3
4
5
6
7
        static public void Test()
        {
            Remoting.GetObject3("input")
                .ContinueWith(obj => 
                    WebSharper.JavaScript.Console.Log(obj.Result)
                );
        }

Or alternatively, using async:

1
2
3
4
5
        static async public Task Test()
        {
            var obj = await Remoting.GetObject3("input");
            WebSharper.JavaScript.Console.Log(obj);
        }

In this case, you get a warning where you call Test() but it is ok to ignore, as this is just telling you that the async is not completed when current block continues, but it is started.

Hope this helps!

By on 6/22/2018 5:05 AM ()

Shouldn't WebSharper throw some exception, where c# code would normally begin some blocking operation (Join(), Result, etc )? As for now compiled JS gives erroneous data where normal с# is expected to give some reliability.

By on 6/23/2018 6:02 AM ()

You do get a compile-time (and code service) error if you try to use a method that does not have a JavaScript compilation defined. Most blocking calls are such, like task.RunSynchronously().

But Result is tricky, because it is needed for valid use cases, so it could indeed throw a runtime error instead. I have created a ticket to track this: https://github.com/dotnet-websharper/core/issues/968

By on 6/26/2018 4:35 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper