Cal*_*ter 2 c# asp.net-mvc entity-framework
我有2个项目.第一个项目是一个dll项目,第二个是mvc4网站.在dll中我有一个实体数据模型,我自动生成了DbContext.
在Global.asax中,我使用以下行初始化数据库:
System.Data.Entity.Database.SetInitializer( new DropCreateDatabaseAlways<WebConfigEntities>() );
Run Code Online (Sandbox Code Playgroud)
当我启动网站时,我得到一个TypeLoadException
Server Error in '/' Application.
GenericArguments[0], WebConfigDB.WebConfigEntities, voor System.Data.Entity.IDatabaseInitializer`1[TContext] is in strijd met de beperking van typeparameter TContext.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: GenericArguments[0], WebConfigDB.WebConfigEntities, voor System.Data.Entity.IDatabaseInitializer`1[TContext] is in strijd met de beperking van typeparameter TContext.
Source Error:
Line 46:
Line 47: BundleTable.Bundles.EnableDefaultBundles();
Line 48: }
Line 49: }
Line 50: }
Source File: D:\projecten\MD2400\WebConfig\Global.asax.cs Line: 48
Stack Trace:
[TypeLoadException: GenericArguments[0], WebConfigDB.WebConfigEntities, voor System.Data.Entity.IDatabaseInitializer`1[TContext] is in strijd met de beperking van typeparameter TContext.]
WebConfig.MvcApplication.Application_Start() in D:\projecten\MD2400\WebConfig\Global.asax.cs:48
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
此类错误通常表示不同的程序集以某种方式引用不同版本的EntityFramework.dll.确保所有项目(以及引用程序集的任何其他内容)使用完全相同的版本.此外,请确保您在GAC中没有EntityFramework.dll,或者如果您必须在GAC中拥有它,那么它也与引用的版本相同.
如果您使用的是针对不同版本构建的外部依赖项,并且您无法更改此设置,则可能需要设置绑定重定向以确保CLR适当地解析版本.
| 归档时间: |
|
| 查看次数: |
1677 次 |
| 最近记录: |