开发者

Dblinq reference in ASP.NET Web Service on MonoDevelop causes xsp2 to fault

开发者 https://www.devze.com 2023-01-19 07:23 出处:网络
I am trying to try DBLinq with the sqlite provider inside a simple ASP.NET web service.I am also using MonoDevelop 2.4 and Mono 2.6.7,The project

I am trying to try DBLinq with the sqlite provider inside a simple ASP.NET web service. I am also using MonoDevelop 2.4 and Mono 2.6.7, The project in monodevelop references the DbLinq.dll which by default is set to be Local Copy. I can compile the webservice just fine. By when I try to run it from Monodevelop or using the xsp2 from the command line, xsp2 fails with a number of errors (see below). If I unchecked the Local Copy for the DBLinq.dll reference, xsp2 will execute but the Linq portion of the code does not work. This is also true for the MySQL provider. I think the problem is the when DbLinq is referenced and be locally copied, it also copies the dependent assemblies and one of the assembly is causing xsp2 to choke.

Has anyone encountered this? How can I fix the problem or what is the workaround? Any help is very much appreciated. Below is the sample snippet of the webservice method in the asmx code behind.

[WebMethod]

public string 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 += "; "; 
            } 
    } 

return txt;

}

Of course, this might not be a good way to implement data access and will need to separate the concerns. But for testing purposes, this should at least work.

Here is the error I get when I run xsp2. As I said above, one of the dependent assemblies that DbLinq references and copied locally is causing this to happen. My question is how do I best fix this so it works?

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

** (/usr/lib/mono/2.0/xsp2.exe:2566): WARNING **: Missing method System.Web.Configuration.WebConfigurationManager::get_AppSettings() in assembly /usr/lib/mono/gac/System.Web/2.0.0.0_b03f5f7f11d50a3a/ System.Web.dll, referenced in assembly /usr/lib/mono/gac/Mono.Web/ 2.0.0.0_0738eb9f132ed756/Mono.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566): WARNING **: Missing method System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeCo­nverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) in assembly /home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll, referenced in assembly /usr/lib/mono/gac/ System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566): WARNING **: Missing method System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeCo­nverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) in assembly /home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll, referenced in assembly /usr/lib/mono/gac/ System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566): WARNING **: Missing method System.Configuration.ConfigurationProperty::.ctor(string,Type,object,TypeCo­nverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) in assembly /home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll, referenced in assembly /usr/lib/mono/gac/ System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll

** (/usr/lib/mono/2.0/xsp2.exe:2566): WARNING **: Missing method System.Configuration.ConfigurationProp开发者_运维问答erty::.ctor(string,Type,object,TypeCo­nverter,ConfigurationValidatorBase,ConfigurationPropertyOptions) in assembly /home/ellory/Projects/WebService/WebService/bin/ System.Configuration.dll, referenced in assembly /usr/lib/mono/gac/ System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll Handling exception type TargetInvocationException Message is Exception has been thrown by the target of an invocation. IsTerminating is set to True System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

Server stack trace: at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in :0 at System.Configuration.ConfigInfo.CreateInstance () [0x00000] in :0 at System.Configuration.SectionInfo.CreateInstance () [0x00000] in :0 at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x00000] in :0 at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00000] in :0 at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in :0 at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x00000] in :0 at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path) [0x00000] in :0 at System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection (System.String sectionName) [0x00000] in :0 at System.Web.Hosting.ApplicationHost.SetHostingEnvironment () [0x00000] in :0 at System.AppDomain.DoCallBack (System.CrossAppDomainDelegate callBackDelegate) [0x00000] in :0 at (wrapper remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) at (wrapper xdomain-dispatch) System.AppDomain:DoCallBack (object,byte[]&,byte[]&)

Exception rethrown at [0]: ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Web.Configuration.HostingEnvironmentSection ---> System.MissingMethodException: Method not found: 'System.Configuration.ConfigurationProperty..ctor'. --- End of inner exception stack trace --- at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 --- End of inner exception stack trace --- at (wrapper xdomain-invoke) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) at (wrapper remoting-invoke-with-check) System.AppDomain:DoCallBack (System.CrossAppDomainDelegate) at System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) [0x00000] in :0 at Mono.WebServer.VPathToHost.CreateHost (Mono.WebServer.ApplicationServer server, Mono.WebServer.WebSource webSource) [0x00000] in :0 at Mono.WebServer.XSP.Server.RealMain (System.String[] args, Boolean root, IApplicationHost ext_apphost, Boolean quiet) [0x00000] in :0 at (wrapper remoting-invoke-with-check) Mono.WebServer.XSP.Server:RealMain (string[],bool,Mono.WebServer.IApplicationHost,bool) at Mono.WebServer.XSP.Server.Main (System.String[] args) [0x00000] in :0


DbLinq is the foundation of LINQ to SQL and System.Data.Linq namespace on Mono. So you don't have to deploy/reference the DbLinq assemblies. Forget about DbLinq when you're using Mono.

The LINQ portion of your code fail because the data context is not properly initialized.
You should do :

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"));

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

0

精彩评论

暂无评论...
验证码 换一张
取 消