C# System.Runtime.Serialization.SerializationException:找不到程序集';EntityFramework,版本=6.0.0.0,区域性=中性,PublicKeyToken=xxx';
我有一个使用实体框架6的C# System.Runtime.Serialization.SerializationException:找不到程序集';EntityFramework,版本=6.0.0.0,区域性=中性,PublicKeyToken=xxx';,c#,wpf,entity-framework,serialization,mvvm,C#,Wpf,Entity Framework,Serialization,Mvvm,我有一个使用实体框架6的MVVM-WPF浏览器应用程序。我正在尝试删除数据网格中的一行。我可以删除一行,但当我尝试删除第二行时,出现以下错误: System.Runtime.Serialization.SerializationException:找不到 程序集的EntityFramework,版本=6.0.0.0,区域性=中性, PublicKeyToken=xxx' ViewModelBase: 公共类CommandBase:INotifyPropertyChanged { #区域“INot
MVVM-WPF浏览器应用程序
。我正在尝试删除数据网格中的一行。我可以删除一行,但当我尝试删除第二行时,出现以下错误:
System.Runtime.Serialization.SerializationException:找不到
程序集的EntityFramework,版本=6.0.0.0,区域性=中性,
PublicKeyToken=xxx'
ViewModelBase:
公共类CommandBase:INotifyPropertyChanged
{
#区域“INotifyPropertyChanged成员”
公共事件属性更改事件处理程序属性更改;
//每次设置属性值时都会调用此例程。
//这将//导致事件通过数据绑定通知WPF已发生更改。
受保护的无效OnPropertyChanged(字符串propertyName)
{
var handler=PropertyChanged;
if(处理程序!=null)
{
处理程序(这是新的PropertyChangedEventArgs(propertyName));
}
}
#端区
私人收藏;
公开收集
{
得到
{
if(集合==null)
{
Get();
}
回收;
}
设置{collection=value;
OnPropertyChanged(“集合”);}
}
选择私人T_;
公营部门未获选
{
获取{return\u selected;}
设置{u selected=value;
OnPropertyChanged(“Selected”);}
}
私有ICommand getCommand;
私有ICommand saveCommand;
私人ICommand和removeCommand;
公共ICommand GetCommand
{
得到
{
返回getCommand??(getCommand=newrelaycommand(Get,CanGet));
}
}
受保护的虚拟bool-CanGet()
{
返回true;
}
受保护的虚拟void Get()
{
//返回true;
}
公共ICommand SaveCommand
{
得到
{
返回saveCommand??(saveCommand=newrelaycommand(Save,CanSave));
}
}
受保护的虚拟void Save()
{
//返回true;
}
受保护的虚拟bool CanSave()
{
返回true;
}
公共ICommand delete命令
{
得到
{
返回removeCommand??(removeCommand=newrelayCommand(Delete,CanDelete));
}
}
受保护的虚拟void Delete()
{
}
受保护的虚拟布尔坎德莱特()
{
如果(已选择!=null)
返回true;
其他的
返回false;
}
}
视图模型:
公共类SupplierViewModel:CommandBase
{
公共上下文ctx=新上下文();
受保护的覆盖void Get()
{
ctx.foodSuppliers.ToList().ForEach(supplier=>ctx.foodSuppliers.Local.Add(supplier));
Collection=ctx.foodSuppliers.Local;
}
受保护的覆盖布尔CanGet()
{
返回true;
}
受保护的覆盖无效保存()
{
foreach(集合中的食品供应商项目)
{
if(ctx.Entry(item.State==System.Data.Entity.EntityState.Added)
{
ctx.食品供应商.添加(项目);
}
}
ctx.SaveChanges();
}
受保护的覆盖无效删除()
{
变量id=已选择;
变量supp=(来自ctx.foodSuppliers中的s
其中s.idfoodSupplier==id.idfoodSupplier
选择s.SingleOrDefault();
ctx.食品供应商。移除(供应商);
ctx.SaveChanges();
收集。移除(supp);
}
受保护的虚拟布尔坎德莱特()
{
返回true;
}
}
查看:
App.config:
我已经对您的代码进行了全面测试,删除所有5行(甚至最后一行)效果良好 您的代码需要先选择一行,确保您在DataGrid中选择了一行,然后删除该行。只有当用户在DataGrid中选择一行时,才能禁用命令按钮并启用它 我对您的代码做了以下更改:
public ICommand GetCommand
{
get
{
return getCommand ?? (getCommand = new RelayCommand(p=>this.Get(), p=>this.CanGet()));
}
}
与其他命令类似:
return saveCommand ?? (saveCommand = new RelayCommand(p=>this.Save(), p=>this.CanSave()));
而且
return removeCommand ?? (removeCommand = new RelayCommand(p=>this.Delete(), p=>this.CanDelete()));
第二个解决办法可以是:
打开
工具>Nuget包管理器>包管理器控制台
然后跑
安装软件包entityframework-版本6.0.0.0
请尝试此处发布的解决方案:
我看到这个问题是在随机环境下发生的。例如,昨天我运行了Windows Update并安装了27个附加更新。第二天,该错误开始每隔15分钟左右抛出一次。正在运行的软件没有更改
Windows update似乎正在等待挂起的重新启动。确保服务器正常运行,这个错误就消失了…您是通过NuGet安装EF6的吗?是的,我可以显示更新,有时还可以删除一行。调试应用程序时,引发异常的具体位置是哪里?在ctx.SaveChanges();谢谢你的帮助。我确保选中了一行,并遵循了您所做的更改,但仍然有相同的错误。否,相同。我在问题中添加了App.config。也许我应该指定我的应用程序是WPF浏览器应用程序。进一步改进了答案OK,我的错误应该是因为我在GAC中没有Entityframework.dll。但卸载和安装时,GAC中不会创建任何内容。
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
<connectionStrings>
<add name="xx" connectionString="xxx" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
public ICommand GetCommand
{
get
{
return getCommand ?? (getCommand = new RelayCommand(p=>this.Get(), p=>this.CanGet()));
}
}
return saveCommand ?? (saveCommand = new RelayCommand(p=>this.Save(), p=>this.CanSave()));
return removeCommand ?? (removeCommand = new RelayCommand(p=>this.Delete(), p=>this.CanDelete()));