2013-11-15 46 views
0

我試圖創建一個實現MySQL實體框架的項目。我已經添加了EntityFramework,MySql.Data和MySQL.Data.Entities NuGet包。我也安裝了mysql-connector-net-6.7.4。我試圖刪除和刪除所有這些東西,但我仍然得到下面的錯誤。我已經將它作爲服務器添加到項目中,並且已經能夠打開db並拉下test_table。我已經使用MySQL連接,並能夠通過Visual Studio連接到數據庫。我不斷收到此錯誤。MySQL實體框架試圖添加時拋出異常

它在以下代碼的最後一行失敗。

sql123456Entities context = new sql123456Entities(); 
test_table cookie = new test_table 
{ 
    this_is_cool = "Yes it is", 
    this_is_cooler = 32, 
    but_is_it_the_fonz = "Yeah!" 
}; 

context.test_table.Add(cookie); 

異常消息(內部異常爲null)

{"Could not load file or assembly 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"} 

堆棧跟蹤:

at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) 
    at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) 
    at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) 
    at System.Type.GetType(String typeName) 
    at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow) 
    at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) 
    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup) 
    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key) 
    at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k) 
    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) 
    at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type, Object key) 
    at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r) 
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() 
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) 
    at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key) 
    at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key) 
    at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) 
    at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString) 
    at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) 
    at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) 
    at System.Data.Entity.Internal.LazyInternalConnection.Initialize() 
    at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() 
    at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 
    at System.Data.Entity.Internal.InternalContext.Initialize() 
    at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 
    at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 
    at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() 
    at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) 
    at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) 
    at System.Data.Entity.DbSet`1.Add(TEntity entity) 
    at ConsoleApplication2.Program.Main(String[] args) in c:\Users\recursor\Documents\Visual Studio 2012\Projects\CS3280\Final Project\IR\ConsoleApplication2\Program.cs:line 24 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 
+0

你有什麼版本的組裝,如果有? – ChrisBint

+0

我在所有程序集中都有6.7.4.0以及版本和指向的連接器。我不知道爲什麼它要求這個特定的版本。 – Recursor

+0

db是MySQL 5.5.34所以我更高的版本應該仍然適用它(它要求版本6.5.5)。我只是不明白爲什麼它要求這個版本,以及爲什麼我提供的版本不起作用。我也不知道如何給它一個它想要的,因爲我從最近的NuGet包中獲得了這個。 – Recursor

回答

0

它看起來像有在App.config錯誤。在運行時,有依賴程序集綁定重定向不正確。我必須運行EF5,因爲這是MySQL支持的最後一個EF版本。所以我不得不改變EF綁定到這個:

<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> 
相關問題