3

I am trying to include a c# servlet CompanyListService.cs in gwan csp folder and getting a compile error 'The type or namespace name `PropertyManagement' could not be found. Are you missing a using directive or an assembly reference?'

PropertyManagement.sql.dll is in the same folder. Also tried to install it in GAC and no luck.

if use, 'mcs CompanyListService.cs -r:PropertyManagement.Sql.dll', it resolves the assembly

Existing Hello.cs and Loan.cs working fine. Any help will be appreciated?

Thanks Ram

// C servlet example for the G-WAN Web Application Server 
// http://gwan.ch/
// hello.cs: G-WAN supports .NET C# servlets

using System;
using System.Collections.Generic;
//using PropertyManagement.Sql;
//using System.Runtime.Serialization.Json;
using System.Text;

public class CompanyListService
{
   public static int Main(string[] args)
   {
    PropertyManagement.Sql.CompanyRepository Repository = new PropertyManagement.Sql.CompanyRepository();
    List<PropertyManagement.Sql.Company> CompanyList = Repository.GetCompanyList();

    //string json = JsonSerializer<List<Company>>(CompanyList);

        Gwan.xbufCat(Gwan.getReply(args[0]), "test");
        return 200; // HTTP status (200:'OK')
   }
}
Gil
  • 3,279
  • 1
  • 15
  • 25

2 Answers2

0

The official documentation does not mention it but loading dynamically your assemblies is not only possible but will offer more flexibility than the traditional ways to do it.

After all, that's what shared libraries are for. Kudos to C# for not having missed that point.

Besides, G-WAN looks for Mono libraries under the /usr/lib/mono path and for user-defined assemblies (like the G-WAN API by the way) in the /gwan/.../libraries/cs directory.

Community
  • 1
  • 1
Gil
  • 3,279
  • 1
  • 15
  • 25
  • Thanks for the Quick reply. I tried to add the dll to GAC and also tried copy the dll to /usr/lib/mono and sub folders and still not able to resolve the reference. I am not sure about performance when loading assemblies using reflection or dynamic loading. any suggestions to make the shared dlls work with gwan? – user3265697 Feb 04 '14 at 11:27
  • Loading dynamic libraries is either done by you manually or by the Mono runtime - either way, it will take as much time and you can use a flag to do it only the first time a servlet is executed. Did you try copying your C# DLL to the dedicated **/gwan/.../libraries/cs** directory? That's where G-WAN's API is defined, and it is properly resolved. – Gil Feb 05 '14 at 06:23
  • I've put it in GAC, /cs, /usr/lib/mono - it doesnot resolve, while code changes in gwan_api reflecting – Igor Golodnitsky Oct 14 '14 at 18:42
  • Using one of the G-WAN scripts at startup, you can load the library in the G-WAN memory-space, and then register its functions in the G-WAN API C# class exported in the /gwan/.../libraries/cs directory. Then your servlets will be able to use any extended C code you wrote, whether this is G-WAN C API function C# wrappers or your own C functions. – Gil Oct 18 '14 at 12:14
  • when you compile servlets - what pkg-config do you use? – Igor Golodnitsky Oct 19 '14 at 22:03
  • We don't modify anything either in the system or in the mono runtime settings. – Gil Oct 20 '14 at 15:22
  • If you add special pkg-config while compiling, I could add there libraries I need. $mcs hello.cs -pkg:dotnet – Igor Golodnitsky Oct 22 '14 at 09:48
  • Also I found that gwan compiles only gwan_api.cs file, not any other names in libraries/cs folder. – Igor Golodnitsky Oct 22 '14 at 09:52
  • Since mono does not support the **pragma** keyword (nor any equivalent) we would have to use a comment at the top of the source code file to specify dependencies (like Google Go if I remember well). If you are interested in testing such a feature, contact the G-WAN team to get a test release. – Gil Oct 23 '14 at 11:23
0

Per the request of another G-WAN + C# user (Igor), the following features have been added in G-WAN v4.12.21:

  • $MONO_PATH is created to include the directory /.../[gwan]/libraries/cs/dll

  • *.dll files located under [gwan]/libraries/cs/dll are added with -pkg:lib1,lib2...

  • any library specified by the line:

    // pragma link libname[,libname,...]

    ...in a *.cs source code file is added with the "-pkg:" switch.

Hope it helps.

Gil
  • 3,279
  • 1
  • 15
  • 25