ServiceStack using DotNetStandard Service Model in .Net framework web project

依然范特西╮ 提交于 2020-01-11 10:37:34

问题


We recently created a new DotNetCore web service using ServiceStack. The ServiceModel project is a DotNet Standard class library v2.0.

I am getting compiling errors while referencing the new ServiceModel from our existing web services that were written in DotNet Framework 4.6.1. Looks like by referencing the new ServiceModel, it is pulling in ServiceStack.Interfaces.Core which conflict with ServiceStack.Interfaces already referenced in the DotNet Framework project.

We are not looking to upgrade those existing services to DotNetCore yet. Is there a way to consume a DotNet Standard ServiceModel in a DotNet Framework web service?

[Edit 1]

Found a similar issue here. My ServiceModel only references ServiceStack.Interfaces.Core(5.1.0). The .net Framework project is targeting v4.6.1 and using ServiceStack v4.5.8. Do I need to upgrade to the latest Service Stack to make it work?

[Edit 2]

Upgraded the ServiceStack version to 5.1.0 in the .net Framework project. That fixed those Service not implementing IServiceClient errors. However, now I am getting

  • The type 'IReturn<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null'.

  • The type arguments for method 'IServiceGateway.Send(object)' cannot be inferred from the usage. Try specifying the type arguments explicitly.


回答1:


If you want to support both classic ASP.NET Framework project and a .NET Core project you need to multi target. See this previous answer for details:

https://stackoverflow.com/a/49417944/85785

If you just want to support an ASP.NET Core .NET Framework project and a .NET Core project (I.e. both ASP.NET Core projects) you can reference ServiceStack’s *.Core projects which only contains .NET Standard builds.

Alternatively you can avoid the binary coupling of sharing your ServiceModel.dll project and have the classic ASP.NET projects reference your DTOs via C# Add ServiceStack Reference.



来源:https://stackoverflow.com/questions/51238152/servicestack-using-dotnetstandard-service-model-in-net-framework-web-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!