Ali
Ali

Reputation: 1678

ServiceStack Service startup error

I am using the below code but I am getting error on this line appHost.Start(listeningOn).

I deleted bin and obj folders, and even restarted Visual Studio, but the error persists:

Here is the code:

var listeningOn = $"http://*:{Globals.RestServicePort}/";
var appHost = new AppHost();
appHost.Init();
appHost.Start(listeningOn);

and this is the error:

The process cannot access the file because it is being used by another process

StackTrace:

at ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.Start(String urlBase, WaitCallback listenCallback) at ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.Start(String urlBase) at NotifierServer.WindowsService.NotificationService.Start() in E:\dev\projectname\WindowsService\mService.cs:line 23

AppHost Class:

public class AppHost : AppHostHttpListenerBase
{
    public AppHost()
        : base("HttpListener Self-Host", typeof(NotifierRestService).Assembly)
    {
        ////disable metadata
        //SetConfig(new EndpointHostConfig
        //{
        //    EnableFeatures = Feature.All.Remove(Feature.Metadata)
        //});
    }

    public override void Configure(Funq.Container container)
    {
        container.Register<IResourceManager>(new ConfigurationResourceManager());

        Plugins.Add(new AuthFeature(() => new AuthUserSession(),
            new IAuthProvider[]
            {
                new BasicAuthProvider(), //Sign-in with HTTP Basic Auth
                new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
            }));

        Plugins.Add(new RegistrationFeature());

        // use redis cache server
        container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
        container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());

        // for authentication
        var dbFactory = new OrmLiteConnectionFactory(Globals.ConnectionStringNotifier,
            ServiceStack.OrmLite.PostgreSqlDialect.Provider);

        var userRep = new OrmLiteAuthRepository(dbFactory);
        container.Register<IUserAuthRepository>(userRep);

        // create necessary auth tables
        userRep.CreateMissingTables();
    }

Upvotes: 0

Views: 355

Answers (1)

mythz
mythz

Reputation: 143284

You need to include the full StackTrace with the Exception, the generic ServiceStack Startup code provided is inconsequential to the Error you're receiving.

The Exception is indicating you're trying to access a file that is used by another process. You first need to identify what file has the issue, then you can use Process Explorer to find out which process is locking it.

Also running on a low port number requires Admin permissions which you can avoid by choosing a port number >2000.

Upvotes: 1

Related Questions