Aws-lambda-dotnet: Menyebarkan dengan Visual Studio 2017 gagal

Dibuat pada 3 Apr 2017  ·  10Komentar  ·  Sumber: aws/aws-lambda-dotnet

Saya baru saja mengambil proyek VS 2015 dan dikompilasi serta disebarkan ke Lambda dengan VS 2017.

Ini adalah hasilnya:

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
Exception has been thrown by the target of an invocation.: TargetInvocationException
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction..ctor()
The given key was not present in the dictionary.: KeyNotFoundException
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)
at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)
at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)
at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)
at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.<GetCandidates>d__4.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__157`2.MoveNext()
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)
guidance

Komentar yang paling membantu

Solusi Saya: Buka file csproj dan atur PreserveCompilationContext ke false.
<PreserveCompilationContext>false</PreserveCompilationContext>

Penjelasan lebih lanjut:
Proyek VS 2017 menyetel PreserveCompilationContext ke true. Ini berarti, ketika Anda mempublikasikan/menyebarkan, VS memancarkan folder "ref" dengan banyak rakitan yang sama dengan folder publikasi root. Saya menduga ada sesuatu yang secara rekursif memindai semua rakitan dan mengacaukannya, tetapi saya tidak yakin sama sekali. Yang saya tahu sejauh ini adalah bahwa saya mengubah pengaturan itu dan sekarang berfungsi, dan saya pikir saya akan membagikan ini untuk melihat apakah itu membantu orang lain.

Semua 10 komentar

Hai @genifycom , dapatkah Anda membagikan file csproj untuk proyek Anda?

Saya mendapatkan kesalahan yang sama dari AddMvc() ketika saya menyebarkan dari VS2017.

Bisakah Anda memberikan file csproj untuk proyek Anda?

Saya mungkin dapat membuat repro yang dapat saya bagikan, preferensi pada metode berbagi?

Repo GitHub dengan kode yang dapat direproduksi di dalamnya akan bagus. Semakin sedikit kode asing di sana, semakin mudah bagi kami untuk mengidentifikasi masalahnya.

Saya baru saja membuatnya menggunakan yeoman di mac. Kemudian ubah proyek menjadi csproj menggunakan dotnet migrate . Ketika diterbitkan dan dipanggil, saya mendapatkan pengecualian berikut:

{
  "errorType": "LambdaException",
  "errorMessage": "An exception was thrown when the constructor for type 'PreviewAspNetCoreWebAPI.LambdaEntryPoint' was invoked. Check inner exception for more details.",
  "cause": {
    "errorType": "TargetInvocationException",
    "errorMessage": "Exception has been thrown by the target of an invocation.",
    "stackTrace": [
      "at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)",
      "at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)",
      "at System.Activator.CreateInstance(Type type, Boolean nonPublic)",
      "at System.Activator.CreateInstance(Type type)"
    ],
    "cause": {
      "errorType": "TargetInvocationException",
      "errorMessage": "Exception has been thrown by the target of an invocation.",
      "stackTrace": [
        "at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)",
        "at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)",
        "at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)",
        "at Microsoft.AspNetCore.Hosting.Internal.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)",
        "at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()",
        "at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()",
        "at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()",
        "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction..ctor()"
      ],
      "cause": {
        "errorType": "KeyNotFoundException",
        "errorMessage": "The given key was not present in the dictionary.",
        "stackTrace": [
          "at System.Collections.Generic.Dictionary`2.get_Item(TKey key)",
          "at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)",
          "at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)",
          "at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)",
          "at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String dependency)",
          "at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.<GetCandidates>d__4.MoveNext()",
          "at System.Linq.Enumerable.<SelectManyIterator>d__157`2.MoveNext()",
          "at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()",
          "at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)",
          "at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)",
          "at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)",
          "at PreviewAspNetCoreWebAPI.Startup.ConfigureServices(IServiceCollection services) in /PreviewAspNetCoreWebAPI/src/PreviewAspNetCoreWebAPI/Startup.cs:line 34"
        ]
      }
    }
  }
}

Terima kasih telah mereproduksi @KraigM

Ini adalah masalah pemblokiran bagi saya saat ini.

Solusi Saya: Buka file csproj dan atur PreserveCompilationContext ke false.
<PreserveCompilationContext>false</PreserveCompilationContext>

Penjelasan lebih lanjut:
Proyek VS 2017 menyetel PreserveCompilationContext ke true. Ini berarti, ketika Anda mempublikasikan/menyebarkan, VS memancarkan folder "ref" dengan banyak rakitan yang sama dengan folder publikasi root. Saya menduga ada sesuatu yang secara rekursif memindai semua rakitan dan mengacaukannya, tetapi saya tidak yakin sama sekali. Yang saya tahu sejauh ini adalah bahwa saya mengubah pengaturan itu dan sekarang berfungsi, dan saya pikir saya akan membagikan ini untuk melihat apakah itu membantu orang lain.

@DohMoose yang membuka blokir saya juga. Sepertinya ini kemungkinan masalah dalam migrasi inti dotnet yang tidak menambahkan konteks kompilasi yang salah ke file proyek?

@DohMoose Luar

Untuk konteksnya, saya beralih dari penerapan VS2015 ke VS2017 dan mendapatkan kesalahan itu saat diluncurkan.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat