Anyname Donotcare
Anyname Donotcare

Reputation: 11393

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

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);
        }
    }

Upvotes: 0

Views: 749

Answers (1)

Anyname Donotcare
Anyname Donotcare

Reputation: 11393

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 .

Upvotes: 0

Related Questions