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.