Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy with Visual Studio 2017 fails #93

Closed
genifycom opened this issue Apr 2, 2017 · 10 comments
Closed

Deploy with Visual Studio 2017 fails #93

genifycom opened this issue Apr 2, 2017 · 10 comments
Labels
guidance Question that needs advice or information.

Comments

@genifycom
Copy link

genifycom commented Apr 2, 2017

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)
@gokarnm
Copy link

gokarnm commented Apr 3, 2017

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

@kylegalbraith
Copy link
Contributor

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

@PavelSafronov
Copy link
Contributor

Can you provide the csproj file for your project?

@kylegalbraith
Copy link
Contributor

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

@PavelSafronov
Copy link
Contributor

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.

KraigM added a commit to KraigM/aws-lambda-dotnet-PreviewAspNetCoreWebAPI that referenced this issue Apr 6, 2017
…he project to csproj using `dotnet migrate`.
@KraigM
Copy link

KraigM commented Apr 6, 2017

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

@kylegalbraith
Copy link
Contributor

Thanks for reproducing @KraigM

This is a blocking issue for me currently.

@DohMoose
Copy link

DohMoose commented Apr 8, 2017

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.

@kylegalbraith
Copy link
Contributor

@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?

@jnb-source
Copy link

@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.

@diehlaws diehlaws added guidance Question that needs advice or information. and removed Question labels Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

8 participants