microsoft / service-fabric

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.
https://docs.microsoft.com/en-us/azure/service-fabric/
MIT License
3.03k stars 399 forks source link

Testing a simple stateless service with FabricTransportServiceRemotingListener, throws an exception: Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination (Marshaling to and from COM interface pointers isn't supported) #356

Open abarberenaCPDS opened 5 years ago

abarberenaCPDS commented 5 years ago

Hello SF Team,

I am wondering if your can help and provide some guidance about this exception.

I am following the guide Set up your development environment on Mac OS X. I successfully got it working.

SF cluster Runtime version is 6.4.625.1 SF SDK version in projects is 6.4.617 and 3.3.617

Running the test client, receives the exception:

Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination (Marshaling to and from COM interface pointers isn't supported)

Any ideas what could be causing the mismatch?

Here are a few screenshots and files to review, as well as details of the implementation.

01_SF_Cluster 02_SF_Service 03_SF_Service 04_SF_Service

Code.zip

Using yeoman, I have created a SF app and a stateless service, then, in VS for Mac, I've added 2 more projects to test the service. I have the following project structure:

MyInterfaces is defined as:

`using System.Threading.Tasks; using Microsoft.ServiceFabric.Services.Remoting;

namespace MyInterfaces { public interface IMyStatelessService : IService { Task MyMethodAsync(); } }`

MyStatelessService.cs is defined as:

`using System; using System.Collections.Generic; using System.Fabric; using System.Threading.Tasks; using Microsoft.ServiceFabric.Services.Communication.Runtime; using Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime; using Microsoft.ServiceFabric.Services.Remoting.V2.FabricTransport.Runtime; using Microsoft.ServiceFabric.Services.Runtime; using MyInterfaces;

namespace MyStatelessService { internal sealed class MyStatelessService : StatelessService, IMyStatelessService { public MyStatelessService(StatelessServiceContext context) : base(context) { }

    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        **FabricTransportRemotingListenerSettings** settings = new FabricTransportRemotingListenerSettings 
        {
            EndpointResourceName = nameof(IMyStatelessService),
            UseWrappedMessage = true
        };

        return new []{
            new ServiceInstanceListener(context=> new **FabricTransportServiceRemotingListener**(context,this,settings), nameof(IMyStatelessService))
        };
    }

    public Task<string> MyMethodAsync()
    {
        string msg = $"Hello world Service Fabric @ {DateTime.Now}";
        return Task.FromResult(msg);
    }
}

}`

And my TestClient is defined as:

`using System; using System.Threading.Tasks; using Microsoft.ServiceFabric.Services.Remoting.Client; using MyInterfaces;

namespace TestClient { class Program { static async Task Test_StatelessService() { string serviceAddress = "fabric:/MyApp/MyStatelessService";

        IMyStatelessService proxy = ServiceProxy.Create<**IMyStatelessService**>(new Uri(serviceAddress), listenerName: nameof(IMyStatelessService));
        string result = await **proxy.MyMethodAsync**();
        Console.WriteLine(result);
    }

    private static void Test()
    {
        try
        {
            Program.Test_StatelessService().Wait();
            Console.WriteLine("Finished...");
        }
        catch (Exception ex)
        {
            string message = string.Empty;
            if (ex.InnerException!=null)
            {
                message = ex.InnerException.Message;
            }
            else
            {
                message = ex.Message;
            }
            Console.WriteLine($"Error: {message}");
        }
    }

    static void Main(string[] args)
    {
        Console.WriteLine("Test Client...");
        Test();
    }

}

}`

abarberenaCPDS commented 3 years ago

👋 Hey guys,

Any updates @masnider @peterpogorski @suhuruli?

I can confirm that this is still happening, even with the latest and greatest of SF.

"Microsoft.ServiceFabric": "8.0.521", "Microsoft.ServiceFabric.Data": "5.0.521", "Microsoft.ServiceFabric.Diagnostics.Internal": "5.0.521", "Microsoft.ServiceFabric.FabricTransport.Internal": "5.0.521", "Microsoft.ServiceFabric.Services": "5.0.521", "Microsoft.ServiceFabric.Services.Remoting": "5.0.521", "MyInterfaces": "1.0.0", "System.Runtime.Serialization.Primitives": "4.3.0"

image image image