ServiceStack 版本 5 中的混乱 [英] Mess in ServiceStack version 5

查看:60
本文介绍了ServiceStack 版本 5 中的混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个托管在 Windows Sercice 中的 ASP.NET Core 应用程序,所以它是一个 .NETCore 项目,但 TargetFramework 是 .NET Framework.

绑定重定向在这种情况下无济于事,因为 publicKeyToken 为空.

最终 ServiceStackServiceStack.Core 就我而言,它们在 Windows 上具有相同的实现.

因此,解决这个问题的关键是从ServiceStack改变ServiceStack.Api.SwaggerServiceStack.Kestrel的依赖code> 系列到 ServiceStack.Core 系列.

第一步是将程序集文件复制到项目中的packages文件夹中,并将引用方式从PackageReference改为Reference.之后,NuGet 不再管理它们,我们可以修改程序集.

现在编译项目会导致不同的错误,如下所示.

错误 CS0012 在未引用的程序集中定义了类型IPlugin".您必须添加对程序集ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587"的引用.错误 CS0012 在未引用的程序集中定义了类型IPreInitPlugin".您必须添加对程序集ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587"的引用.

它们由 ServiceStack.Api.Swagger 生成,因为它试图链接到 ServiceStack 中的类型.事实上,相同类型存在于 ServiceStack.Core 程序集中,其 publicKeyToken 为 null.

现在我使用工具

选择 ServiceStack 依赖项并清除它们的 publicKeyToken,如上面的屏幕截图所示.

编译,现在一切正常,我不更改任何代码.

根本问题是ServiceStack把依赖从ServiceStack.Core家族改成了ServiceStack家族.

我个人建议 ServiceStack 发布另一个依赖于 ServiceStack.Core 的并行包 ServiceStack.Api.Swagger.Core 5.0.2.

I have a ASP.NET Core application hosted in Windows Sercice, so it is a .NETCore project but TargetFramework is .NET Framework. This Microsoft document describes this kind of project.

The application works fine with SerciceStack.Core 1.0.44, here goes the snippet of my project file.

<PackageReference Include="ServiceStack.Core" Version="1.0.44" />
<PackageReference Include="ServiceStack.Kestrel" Version="1.0.44" />
<PackageReference Include="ServiceStack.Text.Core" Version="1.0.44" />
<PackageReference Include="ServiceStack.Api.Swagger.Core" Version="1.0.44" />

Now I am trying to upgrade to version 5.0.2, then I found there are two families of assemblies. ServiceStack 5.0.2 and ServiceStack.Core 5.0.2

Then I tried to head on ServiceStack.Core 5.0.2 direction and found it is totally a mess.

First, there is no ServiceStack.Api.Swagger.Core 5.0.2, the only one is ServiceStack.Api.Swagger 5.0.2 and it is depending on ServiceStack 5.0.2.

Second, ServiceStack.Kestrel 5.0.2 dependencies are in different family of ServiceStack.Kestrel 1.0.44. You can compare the dependencies by opening the links.

So ServiceStack.Kestrel 5.0.2 cannot be used with ServiceStack.Core 5.0.2 any more.

Then I tried the other direction ServiceStack 5.0.2 -- changing all references to the one without Core postfix and encountering another issue.

Which direction should I go in my case?

Best Regards

解决方案

Finnally I get the existing project working with version 5.

First, upgrade the version to 5 as below.

<PackageReference Include="ServiceStack.Api.Swagger" Version="5.0.2" />
<PackageReference Include="ServiceStack.Client.Core" Version="5.0.2" />
<PackageReference Include="ServiceStack.Common.Core" Version="5.0.2" />
<PackageReference Include="ServiceStack.Core" Version="5.0.2" />
<PackageReference Include="ServiceStack.Interfaces.Core" Version="5.0.2" />
<PackageReference Include="ServiceStack.Kestrel" Version="5.0.2" />
<PackageReference Include="ServiceStack.Text.Core" Version="5.0.2" />

Then there are a lot of compilation errors as below.

error CS0433: The type 'IRequest' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0433: The type 'IRequest' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0433: The type 'IReturn<T>' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0433: The type 'Service' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0433: The type 'RouteAttribute' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0246: The type or namespace name 'Verbs' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'Summary' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'Notes' could not be found (are you missing a using directive or an assembly reference?)
error CS0433: The type 'ApiMemberAttribute' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0246: The type or namespace name 'Name' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ParameterType' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'DataType' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'IsRequired' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'Description' could not be found (are you missing a using directive or an assembly reference?)
error CS0433: The type 'IReturn<T>' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0433: The type 'ApiMemberAttribute' exists in both 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'
error CS0246: The type or namespace name 'Name' could not be found (are you missing a using directive or an assembly reference?)
warning MSB3243: No way to resolve conflict between "ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" and "ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587". Choosing "ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" arbitrarily.
warning MSB3243: No way to resolve conflict between "ServiceStack.Client, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" and "ServiceStack.Client, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587". Choosing "ServiceStack.Client, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" arbitrarily.
warning MSB3243: No way to resolve conflict between "ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" and "ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587". Choosing "ServiceStack.Common, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" arbitrarily.
warning MSB3243: No way to resolve conflict between "ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" and "ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587". Choosing "ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" arbitrarily.
warning MSB3243: No way to resolve conflict between "ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" and "ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587". Choosing "ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null" arbitrarily.

These errors are caused by ServiceStack.Api.Swagger and ServiceStack.Kestrel. In previous version, they depend on ServiceStack.Core whose publicKeyToken is null; but in this new version, they depend on ServiceStack whose publicKeyToken exists.

Binding redirection cant help in this case because publicKeyToken is null.

Eventually ServiceStack and ServiceStack.Core they have the same implementation on Windows in my case.

Hence, the key to solve this issue is to change the dependencies of ServiceStack.Api.Swagger and ServiceStack.Kestrel from ServiceStack family to ServiceStack.Core family.

The first step is to copy the assembly files into a packages folder in project and change the reference manner from PackageReference to Reference. After that, NuGet doesnt manage them any more and we can modify the assembly.

Now compiling the project results in different errors like below.

Error   CS0012  The type 'IPlugin' is defined in an assembly that is not referenced. You must add a reference to assembly 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'.  
Error   CS0012  The type 'IPreInitPlugin' is defined in an assembly that is not referenced. You must add a reference to assembly 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'.

They are generated by ServiceStack.Api.Swagger because it is trying to link to the type in ServiceStack. In fact the same type exists in ServiceStack.Core assembly whose publicKeyToken is null.

Now I take use of the tool reflexil to edit ServiceStack.Api.Swagger.dll

Select ServiceStack dependencies and clear their publicKeyToken as it is presented in screenshot above.

Compile and now everything works and I dont change any code.

The root issue is that ServiceStack changes the dependencies from ServiceStack.Core family to ServiceStack family.

Personally I would suggest ServiceStack release another parallel package ServiceStack.Api.Swagger.Core 5.0.2 which depends on ServiceStack.Core.

这篇关于ServiceStack 版本 5 中的混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆