我正在构建针对.NetCore20的服务。我正在CentOS 7.6上使用JetBrains Rider构建这些服务。
我的一个解决方案中有一个非常奇怪的问题,该库在许多其他解决方案中使用而没有任何问题。
因此,如果我查看我的.csproj
文件,它将显示以下内容:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="EasyNetQ" Version="3.3.0" />
<PackageReference Include="EasyNetQ.Serilog" Version="2.3.3" />
<PackageReference Include="MongoDB.Driver" Version="2.6.1" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Enrichers.Context" Version="2.4.0" />
<PackageReference Include="ServiceStack" Version="5.0.2" />
<PackageReference Include="ServiceStack.OrmLite" Version="5.0.2" />
<PackageReference Include="ServiceStack.Redis" Version="5.0.2" />
<PackageReference Include="ServiceStack.Text" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<Reference Include="BediDto, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BediLibs\BediDto\bin\Release\netcoreapp2.0\BediDto.dll</HintPath>
</Reference>
<Reference Include="BediModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BediLibs\BediModels\bin\Release\netcoreapp2.0\BediModels.dll</HintPath>
</Reference>
<Reference Include="BediTools, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BediLibs\BediTools\bin\Release\netcoreapp2.0\BediTools.dll</HintPath>
</Reference>
<Reference Include="BizBus.CommonEnums, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BizBusLibs\BizBus.CommonEnums\bin\Release\netcoreapp2.0\BizBus.CommonEnums.dll</HintPath>
</Reference>
<Reference Include="BizBus.Commons, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BizBusLibs\BizBus.Commons\bin\Release\netcoreapp2.0\BizBus.Commons.dll</HintPath>
</Reference>
<Reference Include="OperationsManagerServer.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\BizBusOpsManagerServer\OperationsManagerServer.ServiceModel\bin\Release\netcoreapp2.0\OperationsManagerServer.ServiceModel.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BizBusDataExchangeServer.ServiceModel\BizBusDataExchangeServer.ServiceModel.csproj" />
</ItemGroup>
</Project>
找不到的程序集是BediDto
和BediModels
,但是当然都存在,并且也在项目的bin
文件夹中:
[tbednarz@linuxdev-tbws2 netcoreapp2.0]$ pwd
/home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/bin/Debug/netcoreapp2.0
[tbednarz@linuxdev-tbws2 netcoreapp2.0]$ ls -all | grep Bedi
-rw-rw-r-- 1 tbednarz tbednarz 16384 Jul 19 15:39 BediDto.dll
-rw-rw-r-- 1 tbednarz tbednarz 3528 Jul 19 15:39 BediDto.pdb
-rw-rw-r-- 1 tbednarz tbednarz 15872 Jul 19 15:39 BediModels.dll
-rw-rw-r-- 1 tbednarz tbednarz 4632 Jul 19 15:39 BediModels.pdb
-rw-rw-r-- 1 tbednarz tbednarz 6144 Jun 4 16:54 BediTools.dll
-rw-rw-r-- 1 tbednarz tbednarz 1096 Jun 4 16:54 BediTools.pdb
我在项目文件中不喜欢的是相对路径(.... \ BediLibs .....),这在运行时是否仍然有效,我不知道....
无论代码是在调试器中启动还是作为Docker容器启动,代码都会失败...
有什么想法吗?我是否需要手动删除某个地方的任何旧缓存文件? 任何帮助将不胜感激。
更新
自@mythz答复以来,我有一些有关抛出该小羊膜的地方的更多详细信息。这是ServiceStack中的最后一个代码:
ServiceController.cs
具有方法public ServiceController Init()
,然后具有方法private List<Type> GetAssemblyTypes(Assembly[] assembliesWithServices)
。在此方法内有一个循环
foreach (Assembly assembliesWithService in assembliesWithServices)
{
str1 = assembliesWithService.FullName;
foreach (Type type in assembliesWithService.GetTypes())
{
if (!this.appHost.ExcludeAutoRegisteringServiceTypes.Contains(type))
{
str2 = type.GetOperationName();
typeList.Add(type);
}
}
}
此语句引发了我捕获的异常:
str1 = assembliesWithService.FullName;
有关详细信息,请参见屏幕截图2:
如果进入该语句,我将使用.NET代码,名为Assembly.cs
的文件,并且使用以下方法:
public virtual Type[] GetTypes()
{
Module[] modules = this.GetModules(false);
int length1 = 0;
Type[][] typeArray1 = new Type[modules.Length][];
for (int index = 0; index < typeArray1.Length; ++index)
{
typeArray1[index] = modules[index].GetTypes();
length1 += typeArray1[index].Length;
}
int destinationIndex = 0;
Type[] typeArray2 = new Type[length1];
for (int index = 0; index < typeArray1.Length; ++index)
{
int length2 = typeArray1[index].Length;
Array.Copy((Array) typeArray1[index], 0, (Array) typeArray2, destinationIndex, length2);
destinationIndex += length2;
}
return typeArray2;
}
语句typeArray1[index] = modules[index].GetTypes();
是导致崩溃的语句。在这里,我还可以看到库中的FileNotFound
异常:
所以问题是为什么会这样。我在很多其他项目中都没有问题地使用了它,所以这很奇怪,但是也许代码为.NET方面的其他开发人员提供了更深入的专业知识,使我可以进一步研究...
更新2
我将软件作为docker映像分发。为了构建它们,我目前使用一些bash脚本。这是我在“问题”解决方案中用来生成本地图像的一个图像:
#!/usr/bin/env bash
publishdir=publish
localimagename=bbinvoiceserver
if [ -d ${publishdir} ]; then
printf "Target directory (%s) already exists, deleting it ...\n" ${publishdir}
rm -rf ${publishdir}
fi
dotnet publish -c "Debug" -o ${publishdir}
# create docker image
docker build -t ${localimagename} -f dockerfile.debug .
if docker image ls | grep -q '<none>'; then
printf "Removing temporary images (<none> <none> ones)....\n"
docker rmi $(docker images -f dangling=true -q)
fi
docker image ls
rm -rf ${publishdir}
“ dotnet publish”的输出为:
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceInterface/BizBusInvoiceServer.ServiceInterface.csproj...
Restoring packages for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceModel/BizBusInvoiceServer.ServiceModel.csproj...
Restoring packages for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/BizBusInvoiceServer.csproj...
Generating MSBuild file /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceModel/obj/BizBusInvoiceServer.ServiceModel.csproj.nuget.g.props.
Restore completed in 441.69 ms for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceModel/BizBusInvoiceServer.ServiceModel.csproj.
Generating MSBuild file /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceInterface/obj/BizBusInvoiceServer.ServiceInterface.csproj.nuget.g.props.
Generating MSBuild file /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/obj/BizBusInvoiceServer.csproj.nuget.g.props.
Restore completed in 949.69 ms for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceInterface/BizBusInvoiceServer.ServiceInterface.csproj.
Restore completed in 978.09 ms for /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/BizBusInvoiceServer.csproj.
BizBusInvoiceServer.ServiceModel -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceModel/bin/Debug/netcoreapp2.0/BizBusInvoiceServer.ServiceModel.dll
BizBusInvoiceServer.ServiceModel -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceModel/publish/
BizBusInvoiceServer.ServiceInterface -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceInterface/bin/Debug/netcoreapp2.0/BizBusInvoiceServer.ServiceInterface.dll
BizBusInvoiceServer.ServiceInterface -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer.ServiceInterface/publish/
BizBusInvoiceServer -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/bin/Debug/netcoreapp2.0/BizBusInvoiceServer.dll
BizBusInvoiceServer -> /home/tbednarz/Projects/BizBusInvoiceServer/BizBusInvoiceServer/publish/
如果我列出了publish
文件夹的内容,它包含了所有这些文件,它抱怨在运行时找不到:
[tbednarz@linuxdev-tbws2 publish]$ ls -l
total 10224
-rwxrw-rw- 1 tbednarz tbednarz 273408 Jun 18 13:00 AutoMapper.dll
-rw-rw-r-- 1 tbednarz tbednarz 16384 Jul 19 15:39 BediDto.dll
-rw-rw-r-- 1 tbednarz tbednarz 3528 Jul 19 15:39 BediDto.pdb
-rw-rw-r-- 1 tbednarz tbednarz 15872 Jul 19 15:39 BediModels.dll
-rw-rw-r-- 1 tbednarz tbednarz 4632 Jul 19 15:39 BediModels.pdb
-rw-rw-r-- 1 tbednarz tbednarz 6144 Jun 4 16:54 BediTools.dll
-rw-rw-r-- 1 tbednarz tbednarz 1096 Jun 4 16:54 BediTools.pdb
-rw-rw-r-- 1 tbednarz tbednarz 10752 Jul 18 14:40 BizBus.CommonEnums.dll
-rw-rw-r-- 1 tbednarz tbednarz 240 Jul 18 14:40 BizBus.CommonEnums.pdb
-rw-rw-r-- 1 tbednarz tbednarz 44032 Jul 18 14:40 BizBus.Commons.dll
-rw-rw-r-- 1 tbednarz tbednarz 15812 Jul 18 14:40 BizBus.Commons.pdb
-rwxr-xr-x 1 tbednarz tbednarz 59392 May 29 09:15 BizBusDataExchangeServer.ServiceModel.dll
-rwxr-xr-x 1 tbednarz tbednarz 16712 May 29 09:15 BizBusDataExchangeServer.ServiceModel.pdb
-rw-rw-r-- 1 tbednarz tbednarz 130372 Jul 20 08:45 BizBusInvoiceServer.deps.json
-rw-rw-r-- 1 tbednarz tbednarz 27648 Jul 20 08:45 BizBusInvoiceServer.dll
-rw-rw-r-- 1 tbednarz tbednarz 5800 Jul 20 08:45 BizBusInvoiceServer.pdb
-rw-rw-r-- 1 tbednarz tbednarz 146 Jul 20 08:45 BizBusInvoiceServer.runtimeconfig.json
-rw-rw-r-- 1 tbednarz tbednarz 273408 Jul 20 08:45 BizBusInvoiceServer.ServiceInterface.dll
-rw-rw-r-- 1 tbednarz tbednarz 66832 Jul 20 08:45 BizBusInvoiceServer.ServiceInterface.pdb
-rw-rw-r-- 1 tbednarz tbednarz 94720 Jul 20 08:45 BizBusInvoiceServer.ServiceModel.dll
-rw-rw-r-- 1 tbednarz tbednarz 24488 Jul 20 08:45 BizBusInvoiceServer.ServiceModel.pdb
-rwxrw-rw- 1 tbednarz tbednarz 186368 Jan 11 2018 CommandLine.dll
-rwxrw-rw- 1 tbednarz tbednarz 92672 May 1 2017 DnsClient.dll
-rwxrw-rw- 1 tbednarz tbednarz 22008 Apr 24 00:44 Microsoft.AspNetCore.Hosting.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 124912 Apr 24 00:44 Microsoft.AspNetCore.Hosting.dll
-rwxrw-rw- 1 tbednarz tbednarz 15352 Apr 24 00:44 Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 73712 Apr 24 00:44 Microsoft.AspNetCore.Http.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 78840 Apr 24 00:44 Microsoft.AspNetCore.Http.dll
-rwxrw-rw- 1 tbednarz tbednarz 38384 Apr 24 00:44 Microsoft.AspNetCore.Http.Extensions.dll
-rwxrw-rw- 1 tbednarz tbednarz 31728 Apr 24 00:44 Microsoft.AspNetCore.Http.Features.dll
-rwxrw-rw- 1 tbednarz tbednarz 276464 Apr 24 00:44 Microsoft.AspNetCore.Server.Kestrel.Core.dll
-rwxrw-rw- 1 tbednarz tbednarz 15864 Apr 24 00:44 Microsoft.AspNetCore.Server.Kestrel.dll
-rwxrw-rw- 1 tbednarz tbednarz 93688 Apr 24 00:44 Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 83440 Apr 24 00:44 Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.dll
-rwxrw-rw- 1 tbednarz tbednarz 66544 Apr 24 00:44 Microsoft.AspNetCore.WebUtilities.dll
-rwxrw-rw- 1 tbednarz tbednarz 19960 Apr 24 00:44 Microsoft.Extensions.Configuration.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 24056 Apr 24 00:44 Microsoft.Extensions.Configuration.Binder.dll
-rwxrw-rw- 1 tbednarz tbednarz 20984 Apr 24 00:44 Microsoft.Extensions.Configuration.CommandLine.dll
-rwxrw-rw- 1 tbednarz tbednarz 24560 Apr 24 00:44 Microsoft.Extensions.Configuration.dll
-rwxrw-rw- 1 tbednarz tbednarz 19960 Apr 24 00:44 Microsoft.Extensions.Configuration.EnvironmentVariables.dll
-rwxrw-rw- 1 tbednarz tbednarz 22000 Apr 24 00:44 Microsoft.Extensions.Configuration.FileExtensions.dll
-rwxrw-rw- 1 tbednarz tbednarz 23544 Apr 24 00:44 Microsoft.Extensions.Configuration.Json.dll
-rw-r--r-- 1 tbednarz tbednarz 36360 Apr 6 16:09 Microsoft.Extensions.DependencyInjection.Abstractions.dll
-rw-r--r-- 1 tbednarz tbednarz 44552 Apr 6 16:09 Microsoft.Extensions.DependencyInjection.dll
-rw-r--r-- 1 tbednarz tbednarz 17904 Apr 6 16:09 Microsoft.Extensions.FileProviders.Abstractions.dll
-rw-r--r-- 1 tbednarz tbednarz 31216 Apr 6 16:09 Microsoft.Extensions.FileProviders.Physical.dll
-rw-r--r-- 1 tbednarz tbednarz 39408 Apr 6 16:09 Microsoft.Extensions.FileSystemGlobbing.dll
-rwxrw-rw- 1 tbednarz tbednarz 14320 Apr 24 00:44 Microsoft.Extensions.Hosting.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 46584 Apr 24 00:44 Microsoft.Extensions.Logging.Abstractions.dll
-rwxrw-rw- 1 tbednarz tbednarz 30704 Apr 24 00:44 Microsoft.Extensions.Logging.dll
-rw-r--r-- 1 tbednarz tbednarz 17928 Apr 6 16:09 Microsoft.Extensions.ObjectPool.dll
-rwxrw-rw- 1 tbednarz tbednarz 26104 Apr 24 00:44 Microsoft.Extensions.Options.dll
-rw-r--r-- 1 tbednarz tbednarz 33288 Apr 6 16:09 Microsoft.Extensions.Primitives.dll
-rwxrw-rw- 1 tbednarz tbednarz 71152 Apr 24 00:44 Microsoft.Net.Http.Headers.dll
-rwxrw-rw- 1 tbednarz tbednarz 451072 May 16 22:31 MongoDB.Bson.dll
-rwxrw-rw- 1 tbednarz tbednarz 632320 May 16 22:31 MongoDB.Driver.Core.dll
-rwxrw-rw- 1 tbednarz tbednarz 639488 May 16 22:31 MongoDB.Driver.dll
-rwxrw-rw- 1 tbednarz tbednarz 639488 Jun 18 2017 Newtonsoft.Json.dll
-rw-rw-r-- 1 tbednarz tbednarz 87552 Jul 16 14:59 OperationsManagerServer.ServiceModel.dll
-rw-rw-r-- 1 tbednarz tbednarz 23292 Jul 16 14:59 OperationsManagerServer.ServiceModel.pdb
drwxrwxr-x 15 tbednarz tbednarz 4096 Jul 20 08:45 runtimes
-rwxrw-rw- 1 tbednarz tbednarz 8192 Mar 7 06:12 Serilog.AspNetCore.dll
-rwxrw-rw- 1 tbednarz tbednarz 116736 Dec 3 2017 Serilog.dll
-rwxrw-rw- 1 tbednarz tbednarz 6656 Jan 14 2018 Serilog.Enrichers.Context.dll
-rwxrw-rw- 1 tbednarz tbednarz 5120 Nov 13 2016 Serilog.Enrichers.Thread.dll
-rwxrw-rw- 1 tbednarz tbednarz 27136 May 1 08:16 Serilog.Exceptions.dll
-rwxrw-rw- 1 tbednarz tbednarz 11264 Aug 18 2017 Serilog.Extensions.Logging.dll
-rwxrw-rw- 1 tbednarz tbednarz 8192 Jul 5 2016 Serilog.Formatting.Compact.dll
-rwxrw-rw- 1 tbednarz tbednarz 32768 Oct 22 2017 Serilog.Sinks.Console.dll
-rwxrw-rw- 1 tbednarz tbednarz 26624 Oct 29 2017 Serilog.Sinks.File.dll
-rwxrw-rw- 1 tbednarz tbednarz 1088512 Jan 2 2018 ServiceStack.Api.Swagger.dll
-rwxrw-rw- 1 tbednarz tbednarz 189440 Jan 2 2018 ServiceStack.Client.dll
-rwxrw-rw- 1 tbednarz tbednarz 411136 Jan 2 2018 ServiceStack.Common.dll
-rwxrw-rw- 1 tbednarz tbednarz 1517568 Jan 2 2018 ServiceStack.dll
-rwxrw-rw- 1 tbednarz tbednarz 138240 Jan 2 2018 ServiceStack.Interfaces.dll
-rwxrw-rw- 1 tbednarz tbednarz 575488 Jan 2 2018 ServiceStack.OrmLite.dll
-rwxrw-rw- 1 tbednarz tbednarz 286208 Jan 2 2018 ServiceStack.Redis.dll
-rwxrw-rw- 1 tbednarz tbednarz 398848 Jan 2 2018 ServiceStack.Text.dll
-rwxrw-rw- 1 tbednarz tbednarz 32504 Jul 19 2017 System.Net.Http.WinHttpHandler.dll
-rw-r--r-- 1 tbednarz tbednarz 21944 Apr 6 16:09 System.Runtime.CompilerServices.Unsafe.dll
-rwxrw-rw- 1 tbednarz tbednarz 28568 Jul 25 2017 System.ServiceModel.Primitives.dll
-rw-r--r-- 1 tbednarz tbednarz 60808 Apr 6 16:08 System.Text.Encodings.Web.dll
如您所见,文件BediModels.dll
和BediDto.dll
位于顶部。
答案 0 :(得分:0)
如果这些是项目引用,则应改为引用该项目:
<ProjectReference Include="..\..\BediLibs\BediDto\BediDto.csproj" />
答案 1 :(得分:0)
我可以通过简单地将两个DLL添加到“ root”项目中来解决此问题,尽管它们并不需要直接在其中存在,现在它可以工作了。因此,遵循@mythz建议
但是,如果您要直接引用.dll,我建议您将它们放在本地/ lib文件夹中,并使用脚本来复制它们,而不是尝试引用项目输出文件夹。
似乎是要走的路。但是我相信这是dotnet
构建工具中的某个错误,似乎不能正确地正确解决所有依赖关系(至少在某些未知情况下……)这些类型的问题通常很难找到,因为它们是几乎永远无法正确再现...