【发布时间】:2021-06-07 09:52:56
【问题描述】:
我正在使用 NPOI 构建一个 Excel 到 .bin 控制台应用程序,我想做的是将读取的数据与第一类进行比较,让我解释得更好......
如果我有 Excel 文件:Sample.xlxs
| _valueOne | _valueTwo |
|---|---|
| 0.0f | testString |
然后使用我的应用程序将其转换为数据表(然后对其进行序列化),但在编写数据表之前,我将检查 Excel 文件上的任何错误,例如在最终类中:
public class Sample
{
public float _valueOne;
public string _valueTwo;
}
我想加载这个类来比较从 Excel 文件中得到的值来发现一些错误(比如是一个字符串而不是一个浮点数)
最终类包含在另一个项目中,所以我想知道是否有办法“导入”它。
其实我在用
private static System.Type GetType(
string in_assemblyPath,
string in_className)
{
System.Type typeCur
= System.Type.GetType(in_className);
if (typeCur != null)
{
return typeCur;
}
else
{
Debug.WriteLine(in_assemblyPath + "/" + in_className + ".cs");
try
{
System.Reflection.Assembly asm
= Assembly.LoadFrom(in_assemblyPath + "/" + in_className + ".cs");
typeCur
= asm.GetType(in_className);
if (typeCur != null)
{
return typeCur;
}
}catch(Exception ex )
{
Debug.WriteLine(">>>>>>>>>>> " + "Error On Assembly Load"+" <<<<<<<<<" );
Debug.WriteLine(ex.StackTrace);
Debug.WriteLine(ex.Message);
Debug.WriteLine(">>>>>>>>>>> " + "End Error Report" + " <<<<<<<<<");
}
}
return null;
}
但我收到一条错误消息:该模块应包含程序集清单。
【问题讨论】:
-
看起来您正在尝试加载
.cs文件,它不是程序集 - 它是需要构建以生成程序集的代码文件。你能澄清你的整个设置 - 你为什么要尝试获取 Excel 文件并将其转换为数据表?也许有关此目的的一些背景知识可以帮助我们了解您正在尝试做什么以及如何最好地实现它。
标签: c# .net-assembly dynamic-loading