无法加载文件或程序集'RevitApi'版本= 19.0.0.0,

问题描述 投票:0回答:2

我过去几周一直在为“Revit”程序创建一个加载项。这一切都很好,但突然间,每当我尝试将我的DataSourceDataGridView设置为我的班级getEntiteitenData时,我得到错误:

使用下拉列表时出错:无法加载文件或程序集“RevitAPI,Version = 19.0.0.0,Culture = neutral,PublicKeyToken = null”或其依赖项之一。该系统找不到指定的文件。

我没有更改文件位置或任何内容,并且所有类中都加载了.dll。另外,我在另一个DataGridView上使用了这种方法,它工作正常。到目前为止我能说的唯一区别是它工作的那个,它是一个Windows Form,另一个,它不起作用,它是一个user control

最令人讨厌的是,当它出现错误时,它会关闭我的视觉工作室。

任何帮助将不胜感激!

enter image description here

c# visual-studio winforms user-controls .net-assembly
2个回答
0
投票

你可以试试这个。

将此行添加到应用程序的主类中。必须先调用它。

        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;
        }

这将仅加载应用程序文件夹中的程序集或您定义的文件夹


0
投票

出于某种原因,问题只发生在我从设计器窗口绑定数据时。我尝试用代码绑定它,这很有效!

将我添加到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();

现在一切似乎都有效了,我想要绑定的列现在是设计师的实际视觉效果。

© www.soinside.com 2019 - 2024. All rights reserved.