我过去几周一直在为“Revit”程序创建一个加载项。这一切都很好,但突然间,每当我尝试将我的DataSource
的DataGridView
设置为我的班级getEntiteitenData
时,我得到错误:
使用下拉列表时出错:无法加载文件或程序集“RevitAPI,Version = 19.0.0.0,Culture = neutral,PublicKeyToken = null”或其依赖项之一。该系统找不到指定的文件。
我没有更改文件位置或任何内容,并且所有类中都加载了.dll
。另外,我在另一个DataGridView
上使用了这种方法,它工作正常。到目前为止我能说的唯一区别是它工作的那个,它是一个Windows Form
,另一个,它不起作用,它是一个user control
最令人讨厌的是,当它出现错误时,它会关闭我的视觉工作室。
任何帮助将不胜感激!
你可以试试这个。
将此行添加到应用程序的主类中。必须先调用它。
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
将此代码添加到您的应用程序。
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string assemblyFullName;
System.Reflection.AssemblyName assemblyName;
assemblyName = new System.Reflection.AssemblyName(args.Name);
assemblyFullName = System.IO.Path.Combine(
System.IO.Path.Combine(
System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), <You folder>), assemblyName.Name + ".dll");
if (System.IO.File.Exists(assemblyFullName))
return System.Reflection.Assembly.LoadFile(assemblyFullName);
else
return null;
}
这将仅加载应用程序文件夹中的程序集或您定义的文件夹
出于某种原因,问题只发生在我从设计器窗口绑定数据时。我尝试用代码绑定它,这很有效!
将我添加到Designer.Cs后:
private System.Windows.Forms.BindingSource getEntiteitenDataBindingSource3;
this.getEntiteitenDataBindingSource3 = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.getEntiteitenDataBindingSource3)).BeginInit();
this.entiteitenGrid.DataSource = this.getEntiteitenDataBindingSource3;
this.getEntiteitenDataBindingSource3.DataSource = typeof(getEntiteitenData);
((System.ComponentModel.ISupportInitialize)(this.getEntiteitenDataBindingSource3)).EndInit();
现在一切似乎都有效了,我想要绑定的列现在是设计师的实际视觉效果。