MikeTWebb
MikeTWebb

Reputation: 9279

AppHostBase.Instance has already been set after already working

I have an ASP.Net WEB API using ServiceStack. The API had been previously working but is now throwing the "AppHostBase.The instance has already been set". I haven't changed any code since the last time I debugged it successfully. But something must have changed.

I am calling the ServiceStack Assembly in AppHost.cs:

[assembly: WebActivator.PreApplicationStartMethod(typeof(App_Start.AppHost), "Start")]

Then in the Start method:

public static void Start()
{
    new AppHost().Init();
}

This then fires the configure method which throws the error. Any ideas why the "AppHostBase.The instance has already been set" error has suddenly shown up?

Upvotes: 1

Views: 57

Answers (1)

mythz
mythz

Reputation: 143369

Maybe you have multiple PreApplicationStartMethod registrations somewhere? Or some other reflection functionality invoking this code.

The Exception indicates that the AppHost initialization is being called twice, you can try checking using a static flag to verify that it's being called twice, e.g:

static hasInit = false;
public static void Start()
{
    if (hasInit) throw new Exception("Start() Called twice");
    new AppHost().Init();
    hasInit = true;
}

Upvotes: 1

Related Questions