2017-01-27 1 views
2

저는 nopCommerce 기반 프로젝트에서 작업 중입니다. 사용자 지정 엔터티를 업데이트하기 위해 EF 마이그레이션을 사용하려고합니다. 그래서 다음 명령을 실행어셈블리에서 컨텍스트 유형을 찾을 수 없습니다. EF6

Enable-Migrations -StartUpProjectName nop.web -ContextProjectName Nop.Plugin.Payments.Deposit -verbose 

및 오류 얻을 :

Using StartUp project 'Nop.Web'. 
System.Data.Entity.Migrations.Infrastructure.MigrationsException: No context type was found in the assembly 'Nop.Plugin.Payments.Deposit'. 
    at System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType, String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextTypeRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextType(String contextTypeName) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
No context type was found in the assembly 'Nop.Plugin.Payments.Deposit'. 

컨텍스트 클래스는 다음과 같이 정의된다 : 제작 한

public class DepositTransactionObjectContext : DbContext, IDbContext 
{ 
    public DepositTransactionObjectContext(string nameOrConnectionString) : base(nameOrConnectionString) { } 

    public DepositTransactionObjectContext() { } 

    public IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters) where TEntity : BaseEntity, new() 
    { 
     throw new System.NotImplementedException(); 
    } 

    public IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] parameters) 
    { 
     throw new System.NotImplementedException(); 
    } 

    public int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction = false, int? timeout = null, params object[] parameters) 
    { 
     throw new System.NotImplementedException(); 
    } 

    public void Detach(object entity) 
    { 
     throw new System.NotImplementedException(); 
    } 

    public bool ProxyCreationEnabled { get; set; } 
    public bool AutoDetectChangesEnabled { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.Configurations.Add(new DepositTransactionMap()); 

     base.OnModelCreating(modelBuilder); 
    } 

    public string CreateDatabaseInstallationScript() 
    { 
     return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript(); 
    } 

    public void Install() 
    { 
     //It's required to set initializer to null (for SQL Server Compact). 
     //otherwise, you'll get something like "The model backing the 'your context name' context has changed since the database was created. Consider using Code First Migrations to update the database" 
     Database.SetInitializer<DepositTransactionObjectContext>(null); 

     Database.ExecuteSqlCommand(CreateDatabaseInstallationScript()); 
     SaveChanges(); 
    } 

    public void Uninstall() 
    { 
     this.DropPluginTable("DepositTransaction"); 
    } 

    public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity 
    { 
     return base.Set<TEntity>(); 
    } 
} 

빈 프로젝트가 마이그레이션을 활성화 . 내가 추가 마이그레이션을 실행할 때 나는 오류 다음 얻을

namespace Nop.Plugin.Payments.Deposit.Migrations 
{ 
    using Data; 
    using System.Data.Entity.Migrations; 

    internal sealed class Configuration : DbMigrationsConfiguration<DepositTransactionObjectContext> 
    { 
     public Configuration() 
     { 
      AutomaticMigrationsEnabled = true; 
     } 

     protected override void Seed(DepositTransactionObjectContext context) 
     { 
     } 
    } 
} 

을 :

Using StartUp project 'Nop.Web'. 
Using NuGet project 'Nop.Plugin.Payments.Deposit'. 
System.Data.Entity.Migrations.Infrastructure.MigrationsException: No migrations configuration type was found in the assembly 'Nop.Plugin.Payments.Deposit'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). 
    at System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType, String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName) 
    at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
No migrations configuration type was found in the assembly 'Nop.Plugin.Payments.Deposit'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). 

내가 같은 질문을 많이 읽고은 다음과 같습니다 그래서 그 때 나는 Configuration.cs를 복사 조정했습니다 그 이유는 Enable-Migrations cmdlet (컨텍스트가 정의되지 않은 cmdlet)에 잘못된 프로젝트가 지정된 이유였습니다. 그러나 당신이 볼 수있는 것처럼 그것은 나의 경우가 아닙니다.

그 밖의 이유는 무엇입니까?

답변

2

Soooo 문제를 해결할 수있었습니다.

조사를 위해 Entity Framework의 소스를 다운로드하고 예외 스택에 언급 된 모든 방법을 확인했습니다. 메소드 System.Data.Entity.Utilities.TypeFinder.FindType에서 내가 찾은 같은 명령 :

var types = _assembly.GetAccessibleTypes() 
           .Where(t => baseType.IsAssignableFrom(t)); 

) (GetAccessibleTypes에 나는이 발견 방법 나를 인도 :

return assembly.DefinedTypes.Select(t => t.AsType()); 

갖는 DefinedTypes을 결과는 EMP이었다

$a = [System.Reflection.Assembly]::LoadFrom("P:\nopCommerce\Presentation\Nop.Web\Plugins\Payments.Deposit\Nop.Plugin.Payments.Deposit.dll") 
$a.DefinedTypes 

: System.Reflection.Assembly 클래스의 속성 나는이 속성을 PowerShell에서 내 어셈블리를로드하고 점점 수동으로이 속성을 얻기 위해 노력했습니다있다 모든 타입이 전혀 없었던 것처럼. 내가 LoaderException 속성을 선택하면

Exception calling "GetTypes" with "0" argument(s): "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."

내가 찾은 다음 :

$Error[0].Exception.InnerException.LoaderExceptions 

$a.GetTypes() 

결과가 오류라고 :

그래서 나는 다른 방법으로 유형을 얻기 위해 노력

Could not load file or assembly 'Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'Nop.Services, Version=3.8.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

보였습니다.NET은 모든 어셈블리를로드하려고했는데 내 어셈블리가 의존했고 물론 같은 폴더에 있지 않았기 때문에 공유 할 수 없었고 다른 위치에 있으며 프로젝트가 아니라 프로젝트 시작으로로드되었습니다.

그래서 필요한 모든 어셈블리를 내 폴더와 동일한 폴더에 복사하고 다시 사용하도록 설정하려고했습니다. 이번에는 오류없이 수행되었습니다!

왜 내가 프로젝트를 시작할 때 고려해야 할 모든 어셈블리 자체를로드하지 않는 것이 좋을지 물어 봅니다. 그러나 다소 사소한 문제입니다.

관련 문제