2011-09-07 12 views
12

Pracuję nad aplikacją WWW ASP.Net MVC 3 przy użyciu EF 4.1. Od dzisiaj, ja dostaję ten błąd:System.ArgumentException: Zduplikowana nazwa typu w zespole

System.ArgumentException: zduplikowane nazwy typu w zespole

i nie mogę dowiedzieć się, co jest przyczyną tego. To się dzieje w moim repozytorium podczas wykonywania Znajdź:

public virtual T GetById(long id) 
{ 
    return dbset.Find(id); 
} 

Oto ślad stosu:

[ArgumentException: Duplicate type name within an assembly.] 
    System.Reflection.Emit.ModuleBuilder.CheckTypeNameConflict(String strTypeName, TypeBuilder enclosingType) +9544354 
    System.Reflection.Emit.AssemblyBuilderData.CheckTypeNameConflict(String strTypeName, TypeBuilder enclosingType) +53 
    System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) +178 
    System.Reflection.Emit.ModuleBuilder.DefineType(String name, TypeAttributes attr, Type parent, Type[] interfaces) +118 
    System.Data.Objects.Internal.ProxyTypeBuilder.get_TypeBuilder() +299 
    System.Data.Objects.Internal.ProxyTypeBuilder.CreateType(ModuleBuilder moduleBuilder) +227 
    System.Data.Objects.Internal.EntityProxyFactory.BuildType(ModuleBuilder moduleBuilder, ClrEntityType ospaceEntityType) +63 
    System.Data.Objects.Internal.EntityProxyFactory.TryCreateProxyType(EntityType ospaceEntityType) +193 
    System.Data.Objects.Internal.EntityProxyFactory.GetProxyType(ClrEntityType ospaceEntityType) +104 
    System.Data.Common.Internal.Materialization.Translator.Visit(EntityColumnMap columnMap, TranslatorArg arg) +178 
    System.Data.Query.InternalTrees.EntityColumnMap.Accept(ColumnMapVisitorWithResults`2 visitor, TArgType arg) +16 
    System.Data.Common.Internal.Materialization.Translator.ProcessCollectionColumnMap(CollectionColumnMap columnMap, TranslatorArg arg, ColumnMap discriminatorColumnMap, Object discriminatorValue) +116 
    System.Data.Common.Internal.Materialization.Translator.Visit(SimpleCollectionColumnMap columnMap, TranslatorArg arg) +13 
    System.Data.Query.InternalTrees.SimpleCollectionColumnMap.Accept(ColumnMapVisitorWithResults`2 visitor, TArgType arg) +17 
    System.Data.Common.Internal.Materialization.Translator.TranslateColumnMap(QueryCacheManager queryCacheManager, ColumnMap columnMap, MetadataWorkspace workspace, SpanIndex spanIndex, MergeOption mergeOption, Boolean valueLayer) +314 
    System.Data.Common.Internal.Materialization.TypedShaperFactoryCreator`1.TypedCreate(QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, Boolean valueLayer) +64 
    System.Data.Common.Internal.Materialization.ShaperFactory.Create(Type elementType, QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, Boolean valueLayer) +185 
    System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters) +285 
    System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +696 
    System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +149 
    System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44 
    System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +184 
    System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable`1 sequence) +41 
    System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +59 
    System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +150 
    System.Linq.Queryable.SingleOrDefault(IQueryable`1 source) +265 
    System.Data.Entity.Internal.Linq.InternalSet`1.FindInStore(WrappedEntityKey key, String keyValuesParamName) +602 
    System.Data.Entity.Internal.Linq.InternalSet`1.Find(Object[] keyValues) +124 
    System.Data.Entity.DbSet`1.Find(Object[] keyValues) +12 
    XXXXXXXX.Data.Infrastructure.RepositoryBase`1.GetById(Int64 id) in C:\XXXXXXXX\XXXXXXXX\XXXXXXXX.Data\Infrastructure\RepositoryBase.cs:58 
    MatchesHorsConcours.Service.MatchService.GetMatch(Int32 id) in C:\XXXXXXXX\XXXXXXXX\XXXXXXXX.Service\XxxService.cs:55 
    XXXXXXXX.Controllers.XXXXXXXX.Edit(Int32 id) in C:\XXXXXXXX\XXXXXXXX\XXXXXXXX.Web\Controllers\XxxController.cs:130 
    lambda_method(Closure , ControllerBase , Object[]) +101 
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263 
    System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 
    System.Web.Mvc.Controller.ExecuteCore() +116 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50 
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

Może to być związane z tabeli, w której ja skopiowanego klucza obcego. Zostało to nazwane czymś w rodzaju myKeyId, a teraz mam w tym tabeli wartości myKey1Id i myKey2Id. Sprawdziłem wszędzie w moim kodzie i nie mogę już znaleźć mojegoKeyId.

Komunikat o błędzie jest tak ogólny, że nie wiem, jak wskazać przyczynę tego błędu. Wszelkie porady będą mile widziane.

+0

Och, tak ... i używam bazy pierwszy paradygmat. –

Odpowiedz

2

Wpadłem dziś na ten błąd. Okazało się, że mój model danych nie ma ograniczeń dotyczących obcego i podstawowego klucza w bazie danych. Skopiowałem oryginalną bazę danych do lokalnej bazy danych, aby przyspieszyć wykonanie, ale skopiowałem tylko dane, a nie relacje. Inne błędy miałem w tym kontekście były

an item with the same key has already been added 

i

Unable to update the EntitySet Table because it has a DefiningQuery and no InsertFunction element exists in the ModificationFunctionMapping element to support the current operation 

to wszystko było spowodowane faultive struktury bazy danych

1

wpadł na ten problem dzisiaj. Usunąłem wszystkie moje tabele z pliku Entity Model .edmx, zaktualizowałem mój model z bazy danych (right-click --> update from database).

Potem ponownie skompilowałem i działało dobrze. Taki dziwny błąd.

Używam MVC 4 i Ef 5,0

24

ja hade ten sam błąd.

Zrobiłem czyste rozwiązanie przebudowane i działało.

+2

Naprawiono również mój problem. –

+0

Naprawiono problem z moją wersją – Damith

+0

Mam nadzieję, że to rozwiąże mój problem ... – Pinch

3

Moim rozwiązaniem było wyłączenie usług IIS, a następnie ponowne uruchomienie projektu VS.

IIS shutdown

+0

Tak, pomaga. Dzięki – pstarkov

Powiązane problemy