0
votes

I have inherited a legacy ASP.NET application that I need to support whilst it is decommissioned but am finding that some of the websites will not compile due to the following error:

CS0433: The type 'IHttpHandler' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

The error occurs when the website is compiled in Temporary ASP.NET Files. The offending line in the *.cs file that is created by ASP.NET off the back of the Default.aspx page is:

[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
    public class default_aspx : global::MyWebsite.Default, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler

So the System.Web.IHttpHandler interface that should be used is clearly the one declared in System.Web.dll. However the website has a reference to a business service that itself references ServiceStack.dll because it implements a client to an API that uses ServiceStack. So ServiceStack.dll ends up in the bin directory of the web project upon complication - and ServiceStack.dll also includes a namespace and interface System.Web.IHttpHandler, hence the error.

Given that the reference to ServiceStack is not a direct one from the website I cannot seem to successfully alias the reference such that the ServiceStack interface is not referenced as a global. And the code that causes the error is auto-generated anyway. Is there any other way around this (other than re-writing the API client to use HttpClient rather than a ServiceStack class)?

1

1 Answers

1
votes

Sounds like you’re trying to include a .NET Standard build of ServiceStack.dll that’s meant for .NET Core in a ASP.NET Framework project.

The dependency should either be rebuilt to target (or multi target) ServiceStack’s .NET v4.5 build (which doesn’t define this interface) so only .NET Framework .dll’s are referenced in an ASP.NET project. ServiceStack’s .NET Standard 2.0 dlls should only be used in ASP.NET Core Apps.