aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Deploy with Visual Studio 2017 fails

Open genifycom opened this issue 9 years ago • 10 comments

I just took a VS 2015 project and compiled and deployed to Lambda with VS 2017.

This is the result:

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)

genifycom avatar Apr 02 '17 22:04 genifycom

Hi @genifycom , could you share the csproj file for your project?

gokarnm avatar Apr 03 '17 17:04 gokarnm

I get this same error from AddMvc() when I deploy from VS2017.

kylegalbraith avatar Apr 05 '17 01:04 kylegalbraith

Can you provide the csproj file for your project?

PavelSafronov avatar Apr 05 '17 16:04 PavelSafronov

I might be able to work up a repro one that I could share, preference on sharing method?

kylegalbraith avatar Apr 05 '17 18:04 kylegalbraith

A GitHub repo with the reproducible code in it would be good. The less extraneous code in there, the easier it will be for us to identify the issue.

PavelSafronov avatar Apr 05 '17 18:04 PavelSafronov

I just generated it using yeoman on mac. Then converted the project to csproj using dotnet migrate. When it is published and invoked, I get the following exception:

{
  "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"
        ]
      }
    }
  }
}

KraigM avatar Apr 06 '17 00:04 KraigM

Thanks for reproducing @KraigM

This is a blocking issue for me currently.

kylegalbraith avatar Apr 06 '17 00:04 kylegalbraith

My Solution: Open the csproj file and set PreserveCompilationContext to false. <PreserveCompilationContext>false</PreserveCompilationContext>

Further Explanation: The VS 2017 projects set PreserveCompilationContext to true. This means ,when you publish/deploy, VS emits a "ref" folder with a lot of the same assemblies as the root publish folder. I suspect that something is recursively scanning all assemblies and screwing that up, but i'm not sure at all. All I know so far is that I changed that setting and it now works, and thought I would share this to see if it helps others.

DohMoose avatar Apr 08 '17 14:04 DohMoose

@DohMoose that unblocked me as well. It seems this is likely an issue in the dotnet core migrate not adding the compilation context false to project files?

kylegalbraith avatar Apr 09 '17 01:04 kylegalbraith

@DohMoose Awesome, that resolved the issue for me too. Thank you.

For context, I switched from a VS2015 deployment to a VS2017 and was getting that error on launch.

jnb-source avatar Apr 19 '17 19:04 jnb-source