dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client' .Net Core 2.2 #11676

Closed geffzhang closed 5 years ago

geffzhang commented 5 years ago

I have .net core 2.2.0 installed and I'm trying to run the published docker of my asp.net core mvc application from the deployment folder of the same PC I'm publishing from using Visual Studio 2019.

When I go to run it with k8s , the project starts and spins up the webserver on my 80 port as expected, but when I access the server Kestrel spits out an error message:

 fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLLBBV3878EF", Request id "0HLLBBV3878EF:00000003": An unhandled exception was thrown by the application.
System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.AspNetCore'
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List`1 assemblies)
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
   at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.<>c.<GetReferencePaths>b__8_0(CompilationLibrary library)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable`1 parts, MetadataReferenceFeature feature)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCompilationReferences()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.get_CompilationReferences()
   at Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature.get_References()
   at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.ProcessCore(RazorCodeDocument codeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Process(RazorProjectItem projectItem)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.OnCacheMiss(String normalizedPath)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

this is dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["NuGet.config","NuGet.config"]
COPY ["Weyhd.AuthServer/Weyhd.AuthServer.csproj", "Weyhd.AuthServer/"]
COPY ["abp/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj", "abp/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/"]
COPY ["abp/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj", "abp/identityserver/src/Volo.Abp.IdentityServer.Domain/"]
COPY ["abp/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj", "abp/identity/src/Volo.Abp.Identity.Domain/"]
COPY ["abp/users/src/Volo.Abp.Users.Domain/Volo.Abp.Users.Domain.csproj", "abp/users/src/Volo.Abp.Users.Domain/"]
COPY ["abp/users/src/Volo.Abp.Users.Abstractions/Volo.Abp.Users.Abstractions.csproj", "abp/users/src/Volo.Abp.Users.Abstractions/"]
COPY ["abp/users/src/Volo.Abp.Users.Domain.Shared/Volo.Abp.Users.Domain.Shared.csproj", "abp/users/src/Volo.Abp.Users.Domain.Shared/"]
COPY ["abp/identity/src/Volo.Abp.Identity.Domain.Shared/Volo.Abp.Identity.Domain.Shared.csproj", "abp/identity/src/Volo.Abp.Identity.Domain.Shared/"]
COPY ["abp/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo.Abp.IdentityServer.Domain.Shared.csproj", "abp/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/"]
COPY ["abp/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj", "abp/permission-management/src/Volo.Abp.PermissionManagement.EntityFrameworkCore/"]
COPY ["abp/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo.Abp.PermissionManagement.Domain.csproj", "abp/permission-management/src/Volo.Abp.PermissionManagement.Domain/"]
COPY ["abp/permission-management/src/Volo.Abp.PermissionManagement.Domain.Shared/Volo.Abp.PermissionManagement.Domain.Shared.csproj", "abp/permission-management/src/Volo.Abp.PermissionManagement.Domain.Shared/"]
COPY ["abp/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj", "abp/identity/src/Volo.Abp.Identity.EntityFrameworkCore/"]
COPY ["abp/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo.Abp.Users.EntityFrameworkCore.csproj", "abp/users/src/Volo.Abp.Users.EntityFrameworkCore/"]
COPY ["abp/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo.Abp.AuditLogging.EntityFrameworkCore.csproj", "abp/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/"]
COPY ["abp/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo.Abp.AuditLogging.Domain.csproj", "abp/audit-logging/src/Volo.Abp.AuditLogging.Domain/"]
COPY ["abp/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo.Abp.AuditLogging.Domain.Shared.csproj", "abp/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/"]
COPY ["abp/account/src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj", "abp/account/src/Volo.Abp.Account.Web.IdentityServer/"]
COPY ["abp/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj", "abp/account/src/Volo.Abp.Account.Web/"]
COPY ["abp/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj", "abp/identity/src/Volo.Abp.Identity.AspNetCore/"]
COPY ["abp/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo.Abp.SettingManagement.EntityFrameworkCore.csproj", "abp/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/"]
COPY ["abp/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo.Abp.SettingManagement.Domain.csproj", "abp/setting-management/src/Volo.Abp.SettingManagement.Domain/"]
COPY ["abp/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/Volo.Abp.SettingManagement.Domain.Shared.csproj", "abp/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/"]
COPY ["abp/identity/src/Volo.Abp.Identity.Application.Contracts/Volo.Abp.Identity.Application.Contracts.csproj", "abp/identity/src/Volo.Abp.Identity.Application.Contracts/"]
COPY ["abp/permission-management/src/Volo.Abp.PermissionManagement.Application.Contracts/Volo.Abp.PermissionManagement.Application.Contracts.csproj", "abp/permission-management/src/Volo.Abp.PermissionManagement.Application.Contracts/"]
RUN dotnet restore "Weyhd.AuthServer/Weyhd.AuthServer.csproj"
COPY . .
WORKDIR "/src/Weyhd.AuthServer"
RUN dotnet build "Weyhd.AuthServer.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "Weyhd.AuthServer.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Weyhd.AuthServer.dll"]
pranavkm commented 5 years ago

Does the published application work outside of docker?

geffzhang commented 5 years ago

the published application work outside of docker, only crash in k8s

geffzhang commented 5 years ago

now https://github.com/dotnet/dotnet-docker/blob/master/samples/dotnetapp/dotnet-docker-selfcontained.md with selfcontained docker,Give 2G memory or did it happen OOMKilled

PS C:\Users\geffzhang> kubectl describe pod/weyhdauthserver-7c9d48d987-thp98 -n dev Name: weyhdauthserver-7c9d48d987-thp98 Namespace: dev Node: 10.0.0.17/10.0.0.17 Start Time: Mon, 01 Jul 2019 10:37:11 +0800 Labels: pod-template-hash=3758048543 qcloud-app=weyhdauthserver Annotations: Status: Running IP: 172.16.0.57 Controlled By: ReplicaSet/weyhdauthserver-7c9d48d987 Containers: weyhdauthserver: Container ID: docker://f4d811272adca3293690c5f9019deb84e6aaee8e3206b7069e9c73fb8510b2ad Image: hub.tencentyun.com/weyhd/weyhdauthserver:20190701022301 Image ID: docker-pullable://hub.tencentyun.com/weyhd/weyhdauthserver@sha256:e1d16add45d0ffa3326e023c7dc4a645b695ec1ec6bc9d0bb260073967c373a7 Port: 80/TCP Host Port: 0/TCP State: Running Started: Mon, 01 Jul 2019 10:40:30 +0800 Last State: Terminated Reason: OOMKilled Exit Code: 137 Started: Mon, 01 Jul 2019 10:37:17 +0800 Finished: Mon, 01 Jul 2019 10:40:25 +0800 Ready: True Restart Count: 1 Limits: cpu: 500m memory: 2Gi Requests: cpu: 100m memory: 128Mi Environment: PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ASPNETCORE_URLS: http://+:80 DOTNET_RUNNING_IN_CONTAINER: true ASPNETCORE_VERSION: 2.2.2 ASPNETCORE_ENVIRONMENT: KUBERNTES_CONFIG_MAP_NAME: weyhdauthserver-config KUBERNTES_NAMESPACE: dev Mounts: /app/appsettings.json from config-volumes (rw) /etc/localtime from localtime (rw) /var/run/secrets/kubernetes.io/serviceaccount from default-token-5rc6z (ro) Conditions: Type Status Initialized True Ready True PodScheduled True Volumes: localtime: Type: HostPath (bare host directory volume) Path: /etc/localtime HostPathType: config-volumes: Type: ConfigMap (a volume populated by a ConfigMap) Name: weyhdauthserver-config Optional: false default-token-5rc6z: Type: Secret (a volume populated by a Secret) SecretName: default-token-5rc6z Optional: false QoS Class: Burstable Node-Selectors: Tolerations: Events: Type Reason Age From Message


Normal Scheduled 4m default-scheduler Successfully assigned weyhdauthserver-7c9d48d987-thp98 to 10.0.0.17 Normal SuccessfulMountVolume 4m kubelet, 10.0.0.17 MountVolume.SetUp succeeded for volume "localtime" Normal SuccessfulMountVolume 4m kubelet, 10.0.0.17 MountVolume.SetUp succeeded for volume "config-volumes" Normal SuccessfulMountVolume 4m kubelet, 10.0.0.17 MountVolume.SetUp succeeded for volume "default-token-5rc6z" Normal Pulling 4m kubelet, 10.0.0.17 pulling image "hub.tencentyun.com/weyhd/weyhdauthserver:20190701022301" Normal Pulled 4m kubelet, 10.0.0.17 Successfully pulled image "hub.tencentyun.com/weyhd/weyhdauthserver:20190701022301" Normal Created 1m (x2 over 4m) kubelet, 10.0.0.17 Created container Normal Pulled 1m kubelet, 10.0.0.17 Container image "hub.tencentyun.com/weyhd/weyhdauthserver:20190701022301" already present on machine Normal Started 1m (x2 over 4m) kubelet, 10.0.0.17 Started container

geffzhang commented 5 years ago

Maybe it's about it. https://github.com/dotnet/coreclr/issues/18044

pranavkm commented 5 years ago

@geffzhang I tried a 2.2 application in docker and I'm unable to reproduce it. Would you be able to provide a minimal sample that reproduces the issue?

pranavkm commented 5 years ago

@geffzhang feel free to reopen once you have more details to share.