简体   繁体   中英

Getting error cannot convert from Fabric.StatelessServiceContext to Fabric.ServiceInitializationParameters while building Service Fabric Web Api

I'm getting error while following this tutorial

cannot convert from 'System.Fabric.StatelessServiceContext' to 'System.Fabric.ServiceInitializationParameters' 

while trying to create the Service Fabric Web Api explained in it.

Specifically, I'm getting it in this next line:

 return new[] {
            new ServiceInstanceListener(initParams =>
            new OwinCommunicationListener("api",new Startup(),initParams) )
        };

I haven't tried much, since Azure's Service Fabric is pretty new stuff, so there isn't much out there in terms of other Web Api examples. The tutorial above itself is not even finished yet.

Has anyone got any ideas?

Thanks

So the problem is that there is a typo in the tutorial.

The solution is that _parameters in class OwinCommunicationListener should be declared as StatelessServiceContext , not as ServiceInitializationParameters . The solution is kind of suggested by Visual Studio's potential fixes.

Just to be clear, the original code of the tutorial throwing the error reads:

private readonly IOwinAppBuilder _startup;
private readonly string _appRoot;
private readonly ServiceInitializationParameters _parameters;

private string _listeningAddress;
private IDisposable _serverHandle;

public OwinCommunicationListener(
        string appRoot,
        IOwinAppBuilder startup,
        ServiceInitializationParameters serviceInitializationParameters
        )
    {
        _startup = startup;
        _appRoot = appRoot;
        _parameters = serviceInitializationParameters;
    }

And the correct code is this next one, note the differences in line 3 and 11:

private readonly IOwinAppBuilder _startup;
private readonly string _appRoot;
private readonly StatelessServiceContext _parameters;

private string _listeningAddress;
private IDisposable _serverHandle;

public OwinCommunicationListener(
    string appRoot,
    IOwinAppBuilder startup,
    //  Use StatelessServiceContext, NOT ServiceInitializationParameters 
    StatelessServiceContext serviceInitializationParameters 
        )
    {
        _startup = startup;
        _appRoot = appRoot;
        _parameters = serviceInitializationParameters;
    }

The call remains the same:

return new[] {
            new ServiceInstanceListener(initParams =>
            new OwinCommunicationListener("api",new Startup(),initParams) )
        };

I hope this helps.

For the same tutorial if someone wondering about missing references , here is the list :

using System.Fabric;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Owin.Hosting;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using System.Globalization;using System.Collections.Generic;
using System.Fabric;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;

For installed Nuget packages : (Go to References in project explorer right click > Nuget Package explorer and install following if not there )

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM