Skip to content

dotnet ef migrations add initial throws System.ArgumentNullException on assemblyName #5065

Closed as not planned

Description

@shaunluttin

Error.

> dotnet ef migrations add initial
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: assemblyName
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.DiscoverAssemblyParts(String entryPointAssemblyName)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)

   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
   at AlgaeApi.CloudComputer.Startup.ConfigureServices(IServiceCollection services) in C:\GitHub\2014-102MS-Monitoring\AlgaeApi\Startup.cs:line 29
   --- End of inner exception stack trace ---
   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.EntityFrameworkCore.Design.Internal.StartupInvoker.Invoke(Type type, String[] methodNames, IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Design.Internal.StartupInvoker.ConfigureServices()
   at Microsoft.EntityFrameworkCore.Design.DbContextOperations..ctor(ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String startupProjectDir)
   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations..ctor(AssemblyLoader assemblyLoader, ILoggerProvider loggerProvider, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String startupProjectDir, String rootNamespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__5()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Exception has been thrown by the target of an invocation.

project.json

{
    "compilationOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true
    },
    "dependencies": {

        "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0-*",
        "Microsoft.EntityFrameworkCore.InMemory": "1.0.0-*",
        "Microsoft.EntityFrameworkCore.Commands" : "1.0.0-*",
        "Microsoft.NETCore.App": {
            "type": "platform",
            "version": "1.0.0-rc2-23931"
        }
    },
    "tools": {
        "dotnet-ef": {
            "version": "1.0.0-*",
            "imports": [
                "dnxcore50",
                "portable-net451+win8"
            ]
        }
    },
    "frameworks": {
        "netstandard1.5": {
            "imports": [
                "dnxcore50",
                "portable-net451+win8"
            ]
        }
    }
}

Activity

  1. shaunluttin commented on Apr 14, 2016

    @shaunluttin
    Author

    It turns out there are some things that the EF migrations do not like to see in the Startup class.

    • services.AddMvcCore();
    • services.AddCors();

    If either of those calls are inside ConfigureServices, then the above migrations error occurs.

  2. natemcmaster commented on Apr 14, 2016

    @natemcmaster
    Contributor

    This error is not being thrown from EF code. The change may need to be in MVC. I opened aspnet/Mvc#4479, but tracking here in case we need to change how EF discovers user services.

  3. natemcmaster commented on Apr 14, 2016

    @natemcmaster
    Contributor

    We found the issue. EF does not properly setup "HostingEnvironment" when discovering services, and MVC is not resilient to this. We need to replicate some of the logic in https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs#L180, adapted to EF's settings of course.

  4. rowanmiller commented on Apr 18, 2016

    @rowanmiller
    Contributor

    Closing as this is now tracked as part of #3925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions