C#调用Dll文件后编译不通过,提示没有引用的问题

当Win Form程序调用DLL文件时,添加引用后编译不通过,提示没有引用。解决方案如下:

1.采用反射的方式调用

if (File.Exists(ApplcationConfig.getProperty("ApplicationRootPath") + "\\" + "test.dll"))
{
Assembly assembly = Assembly.LoadFrom(ApplicationConfig.getProperty("ApplicationRootPath") + "\\" + "test.dll");
//string数组,反射调用窗口时传参数使用

string[] entity = new string[]
{
“”,

“”,

“”,
};

ConstructorInfo constructor = assembly.GetType("ImportForm").GetConstructor(new Type[] { typeof(string[]) });
Form myForm = (Form)constructor.Invoke(new object[] { entity });
myForm.ShowDialog();
}
else
{
MessageBox.Show("缺少dll文件!请联系管理员解决");
}

2.原因可能为两个dll的使用目标框架不同,改为一致即可解决。

 

posted @ 2024-06-02 17:12  江渔湖  阅读(4)  评论(0编辑  收藏  举报