I get the above error when calling Init() on my AppHost.
This is on a clean asp.net v 4.5 empty web application with a simple HelloWorld service as per the getting started tutorial.
I'm specifically using the older version of ServiceStack installed with:
Install-Package ServiceStack -Version 3.9.71
Which installs references to:
ServiceStack.dll 3.9.70.0
ServiceStack.Common.dll 3.9.9.0
ServiceStack.Interfaces.dll 3.9.9.0
ServiceStack.OrmLite.dll 3.9.14.0
ServiceStack.OrmLite.SqlServer.dll 1.0.0.0
ServiceStack.Redis.dll 3.9.11.0
ServiceStack.ServiceInterface.dll 3.9.70.0
ServiceStack.Text.dll 4.0.11.0
And the error I get is:
[TypeLoadException: Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
Falck.WebAPI.AppHost..ctor() in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:17
Falck.WebAPI.Global.Application_Start(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:29
[HttpException (0x80004005): Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9865825
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9880168
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
It says it can't load the type, but I've no idea why?
Below is the output from nuget:
Package Manager Console Host Version 2.8.50126.400
Type 'get-help NuGet' to see all available NuGet commands.
PM> Install-Package ServiceStack -Version 3.9.71
Attempting to resolve dependency 'ServiceStack.Common (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'ServiceStack.Text'.
Attempting to resolve dependency 'ServiceStack.Redis (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'ServiceStack.OrmLite.SqlServer (≥ 3.0 && < 4.0)'.
Installing 'ServiceStack.Text 4.0.11'.
You are downloading ServiceStack.Text from Service Stack, the license agreement to which is available at https://servicestack.net/terms. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'ServiceStack.Text 4.0.11'.
Installing 'ServiceStack.Common 3.9.11'.
Successfully installed 'ServiceStack.Common 3.9.11'.
Installing 'ServiceStack.Redis 3.9.11'.
Successfully installed 'ServiceStack.Redis 3.9.11'.
Installing 'ServiceStack.OrmLite.SqlServer 3.9.14'.
Successfully installed 'ServiceStack.OrmLite.SqlServer 3.9.14'.
Installing 'ServiceStack 3.9.71'.
Successfully installed 'ServiceStack 3.9.71'.
Adding 'ServiceStack.Text 4.0.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Text 4.0.11' to Falck.WebAPI.
Adding 'ServiceStack.Common 3.9.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Common 3.9.11' to Falck.WebAPI.
Adding 'ServiceStack.Redis 3.9.11' to Falck.WebAPI.
Successfully added 'ServiceStack.Redis 3.9.11' to Falck.WebAPI.
Adding 'ServiceStack.OrmLite.SqlServer 3.9.14' to Falck.WebAPI.
Successfully added 'ServiceStack.OrmLite.SqlServer 3.9.14' to Falck.WebAPI.
Adding 'ServiceStack 3.9.71' to Falck.WebAPI.
Successfully added 'ServiceStack 3.9.71' to Falck.WebAPI.
This is a breaking change introduced (with good intentions) in NuGet version 2.8. I suspect that @Scott is running version 2.7 or lower of NuGet.
tl;dr;
To solve the problem add -DependencyVersion Highest
to the install-package
command at the Package Management Console in Visual Studio. The full command reads:
Install-Package ServiceStack -Version 3.9.71 -DependencyVersion Highest
Detailed Answer
In the release notes for NuGet version 2.8, a change to dependency resolution is outlined.
The old version found the lowest major and minor versions which satisfied the dependency, and then loaded the highest patch version. The rationale for this was that patch versions are supposed to be for bug fixes, and don't introduce any breaking changes.
But, package developers being package developers, some "patch versions" of packages did introduce breaking changes, so different developers installing packages at different times were getting a different set of packages.
Version 2.8 of NuGet attempts to resolve this problem by also pulling in the lowest patch version which satisfies the criteria. This breaks ServiceStack, and probably a whole host of other packages too.
ServiceStack has a dependency on ServiceStack.Common (>=3.0 && <4.0).
In the old days (NuGet 2.7), this would pull in version 3.9.71 of ServiceStack.Common (highest available patch number), but now it pulls in 3.9.11 (the lowest patch version on the 3.9 major/minor version).
ServiceStack.Common v3.9.11 does not have the version constraint on its dependencies at all, so pulls in version 4 (commercially licensed!) versions of other packages including its own dependency, ServiceStack.Text.
Thankfully, NuGet includes a command line switch to revert to the old behaviour. Details of it are in the release notes (linked to in the tl;dr; section above). In this particular case, adding -DependencyVersion Highest
will get the highest major, minor and patch versions which satisfy the constraint, meaning 3.9.71 versions are pulled in across the board.
I was running in to the same problem and going over by what Scott said on 02/25, I used the following on the Package Manager Console:
Install-Package ServiceStack -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Common -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.OrmLite.SqlServer -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Redis -Version 3.9.71 -IgnoreDependencies
Install-Package ServiceStack.Text -Version 3.9.71 -IgnoreDependencies
This managed to fix the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With