首页 文章

Expando动态对象传递给其他类需要Microsoft.CSharp.dll吗?

提问于
浏览
1

我有一个功能:

string removeFile(HttpContext context,HttpRequest r)
 {       
       dynamic d = new ExpandoObject() ;
       d.ItemCommand = r["itemId"].ToString();
       ...
       ...
       int res = new PolicyDal().Admin_Kits_AttachFile(d); //sending here the d.

在其他类/文件上:

public int Admin_Kits_AttachFile(dynamic d)
   {
        DbCommand command = _webERPDB.GetStoredProcCommand("Admin_Kits_AttachFile");
        _webERPDB.AddInParameter(command, "@ItemCommand", DbType.String, d.ItemCommand);

发生以下错误:

无法找到编译动态表达式所需的一种或多种类型 . 您是否缺少对Microsoft.CSharp.dll和System.Core.dll的引用

我在FILE SYSTEM中找到DLL后引用,因为它不在常规的添加引用菜单中 .

这是为什么 ?为什么它不会编译?为什么他们没有把dll放在正常的添加参考菜单中? (我必须在文件系统中找到dll ...)

2 回答

  • 4

    该程序集包含DLR . 如果需要在应用程序中使用动态分派,则必须引用它 . 在VS 2010(控制台,WinForms,ASP.NET,类库)中启动新应用程序时,默认情况下会将其添加为参考 .

    为什么他们没有把dll放在正常的添加参考菜单中?

    实际上他们做了:

    enter image description here

  • 3

    当您使用有关动态对象的某些功能时,总会发生此错误 . 编译器将抛出有关缺少Microsoft.CSharp.dll和System.Core.dll的错误 .

    enter image description here

    导致此问题的原因是所有动态对象都需要在运行时动态生成类,如下图所示 .

    enter image description here

    要解决此问题,您只需添加对“Microsoft.CSharp.dll”的引用,以允许运行时动态编译动态对象,如下图所示 .

    enter image description here

相关问题