Could not load type 'XXX' from assembly 'XXX'. at.OnModelCreating(DbModelBuilder modelBuilder)

c# ef-code-first entity-framework entity-framework-6 visual-studio-2015

Question

After i have built my model i want to review it so i try to use EntityFramework Power tools to get the model visually , but i get the following error :

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not load type 'DomainClasses.CompanyLogo' from assembly 'DomainClasses, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. at DataLayer.FinanceModelContext.OnModelCreating(DbModelBuilder modelBuilder) at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext


My Domain Class which may cause the error :

namespace DomainClasses
{
    public class CompanyLogo
    {
        public byte[] Logo { get; set; }

        public int CompanyId { get; set; }

        public virtual Company Company { get; set; }
    }
}

The Configuration file :

public class CompanyLogoMappings:EntityTypeConfiguration<CompanyLogo>
    {
        public CompanyLogoMappings()
        {
            this.HasKey(c => c.CompanyId);
            this.HasRequired(c => c.Company).WithOptional(cl => cl.CompanyLogo);
        }
    }
1
0
7/29/2016 1:37:55 PM

Accepted Answer

After many trails , i find why this error appear.

I added the domain class CompanyLogo after i had generated the model through EF power tools .

So i restart the VS and building the Domain Classes project and run the tool , so it works .

0
7/31/2016 10:27:24 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow