【问题标题】:Dblinq reference in ASP.NET Web Service on MonoDevelop causes xsp2 to faultMonoDevelop 上 ASP.NET Web 服务中的 Dblinq 引用导致 xsp2 出错
【发布时间】:2011-04-23 20:39:29
【问题描述】:

我正在尝试在一个简单的 ASP.NET 网络中使用 sqlite 提供程序来尝试 DBLinq 服务。我也在使用 MonoDevelop 2.4 和 Mono 2.6.7,该项目 在 monodevelop 中引用 DbLinq.dll,默认情况下设置为 本地副本。我可以很好地编译网络服务。当我尝试 从 Monodevelop 运行它或从命令行使用 xsp2 xsp2 失败并出现许多错误(见下文)。如果我取消选中本地 复制 DBLinq.dll 参考,xsp2 将执行,但 Linq 部分 的代码不起作用。对于 MySQL 提供程序也是如此。我认为问题是当 DbLinq 被引用并被本地复制时,它也会复制依赖 程序集和其中一个程序集导致 xsp2 阻塞。

有人遇到过吗?我该如何解决问题或问题是什么 解决方法?很感谢任何形式的帮助。下面是示例 在 asmx 代码后面的 webservice 方法的 sn -p。

[网络方法]
公共字符串 getrecord() {

string txt = string.Empty; 

using( DataContext context = 
   new DataContext("DbLinqProvider=Sqlite; Data Source=openemr.db")) 
    {
            var addrtbl = context.GetTable<Addresses>(); 
            var addr = from a in addrtbl 
                    select a; 
            foreach( var i in addr) 
            { 
                    txt += i.City ; 
                    txt += "; "; 
            } 
    } 

返回txt;
}

当然,这可能不是实现数据访问和 将需要分离关注点。但出于测试目的,这 至少应该工作。

这是我在运行 xsp2 时遇到的错误。正如我上面所说,其中一个 DbLinq 引用并在本地复制的依赖程序集是 导致这种情况发生。我的问题是如何最好地解决这个问题 作品?

user@ubuntu:~/Projects/WebService/WebService$ xsp2 --address 127.0.0.1 --port 8889

** (/usr/lib/mono/2.0/xsp2.exe:2566):警告**:缺少方法 System.Web.Configuration.WebConfigurationManager::get_AppSettings() 在 程序集 /usr/lib/mono/gac/System.Web/2.0.0.0_b03f5f7f11d50a3a/ System.Web.dll,在程序集 /usr/lib/mono/gac/Mono.Web/ 中引用 2.0.0.0_0738eb9f132ed756/Mono.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566):警告**:缺少方法 System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeConverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) 在程序集/home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll,在程序集 /usr/lib/mono/gac/ 中引用 System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566):警告**:缺少方法 System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeConverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) 在程序集/home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll,在程序集 /usr/lib/mono/gac/ 中引用 System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566):警告**:缺少方法 System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeConverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) 在程序集/home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll,在程序集 /usr/lib/mono/gac/ 中引用 System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566):警告**:缺少方法 System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeConverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) 在程序集/home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll,在程序集 /usr/lib/mono/gac/ 中引用 System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll 处理异常类型 TargetInvocationException 消息是异常已被调用的目标抛出。 IsTerminating 设置为 True System.Reflection.TargetInvocationException:已引发异常 通过调用的目标。

服务器堆栈跟踪: 在 System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr,System.Reflection.Binder 绑定器, System.Object[] 参数,System.Globalization.CultureInfo 文化) [0x00000] 在:0 在 System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder 绑定器,System.Object[] 参数, System.Globalization.CultureInfo 文化)[0x00000] 在:0 在 System.Reflection.ConstructorInfo.Invoke (System.Object[] 参数)[0x00000] in :0 在 System.Activator.CreateInstance (System.Type 类型,布尔 非公共)[0x00000] 在:0 在 System.Configuration.ConfigInfo.CreateInstance () [0x00000] 中 :0 在 System.Configuration.SectionInfo.CreateInstance () [0x00000] 中 :0 在 System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo 配置,布尔值 createDefaultInstance) [0x00000] in :0 在 System.Configuration.ConfigurationSectionCollection.get_Item (System.String 名称) [0x00000] in :0 在 System.Configuration.Configuration.GetSection (System.String 路径)[0x00000] 在:0 在 System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String 路径, System.Web.HttpContext 上下文)[0x00000] 在:0 在 System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String 路径) [0x00000] in :0 在 System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection (System.String sectionName) [0x00000] in :0 在 System.Web.Hosting.ApplicationHost.SetHostingEnvironment () [0x00000] 在:0 在 System.AppDomain.DoCallBack (System.CrossAppDomainDelegate callBackDelegate) [0x00000] in :0 在 (wrapper remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) 在(包装器 xdomain-dispatch)System.AppDomain:DoCallBack (对象,字节[]&,字节[]&)

在 [0] 处重新抛出异常: ---> System.TypeInitializationException:异常被抛出 类型初始化器 System.Web.Configuration.HostingEnvironmentSection ---> System.MissingMethodException:找不到方法: 'System.Configuration.ConfigurationProperty..ctor'。 --- 内部异常堆栈跟踪结束 --- 在(包装器托管到本机) System.Reflection.MonoCMethod:InternalInvoke (对象,对象[],System.Exception&) 在 System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr,System.Reflection.Binder 绑定器, System.Object[] 参数,System.Globalization.CultureInfo 文化) [0x00000] 在:0 --- 内部异常堆栈跟踪结束 --- 在(包装器 xdomain-invoke)System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) 在 (wrapper remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) 在 System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String 物理目录)[0x00000] 在:0 在 Mono.WebServer.VPathToHost.CreateHost (Mono.WebServer.ApplicationServer 服务器,Mono.WebServer.WebSource webSource) [0x00000] 在 :0 在 Mono.WebServer.XSP.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 在(包装器远程调用与检查) Mono.WebServer.XSP.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) 在 Mono.WebServer.XSP.Server.Main (System.String[] args) [0x00000] 在:0

【问题讨论】:

    标签: asp.net mono monodevelop dblinq xsp2


    【解决方案1】:

    DbLinq 是 LINQ to SQL 和 Mono 上 System.Data.Linq 命名空间的基础。因此,您不必部署/引用 DbLinq 程序集。使用 Mono 时忘记 DbLinq。

    代码的 LINQ 部分失败,因为数据上下文未正确初始化。
    你应该这样做:

    var context = new DataContext("DbLinqProvider=Sqlite; DbLinqConnectionType=Mono.Data.Sqlite.SqliteConnection, Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756; Data Source=openemr.db");
    // or
    var context = new DataContext(new SqliteConnection("DbLinqProvider=Sqlite; Data Source=openemr.db"));
    

    见:http://www.mono-project.com/Release_Notes_Mono_2.6#LINQ_to_SQL

    【讨论】:

      猜你喜欢
      • 2011-08-11
      • 2010-11-09
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      相关资源
      最近更新 更多