Bug 321916 (MONO79207) - [PATCH] Recent changes in AppDomain loading affect mono-service
Summary: [PATCH] Recent changes in AppDomain loading affect mono-service
Status: RESOLVED FIXED
Alias: MONO79207
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-29 19:06 UTC by Hubert FONGARNAND
Modified: 2007-09-15 21:24 UTC (History)
2 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
mono-service.exe (with a strong name) (in order to insert it into the gac) (10.00 KB, application/octet-stream)
2006-08-30 12:39 UTC, Thomas Wiest
Details
mono-service.diff (894 bytes, patch)
2006-08-30 23:01 UTC, Thomas Wiest
Details | Diff
mono-service2.diff (5.67 KB, patch)
2006-08-30 23:08 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:07:56 UTC


---- Reported by informatique.internet@fiducial.fr 2006-08-29 12:06:30 MST ----

Description of Problem:
Try to load a mono service (System.ServiceProcess), it will fails with a
FileNotFoundException


Steps to reproduce the problem:
1. Write a small service
2. run it with : mono /usr/lib/mono/1.0/mono-service.exe yourservice.exe
3. 

Actual Results:

Unhandled Exception: System.IO.FileNotFoundException: mono-service,
Version=0.0.0.0, Culture=neutral : mono-service, Version=0.0.0.0,
Culture=neutral
  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap
(string,string,bool,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[],System.Security.Policy.Evidence)
  at (wrapper remoting-invoke-with-check)
System.AppDomain:CreateInstanceAndUnwrap
(string,string,bool,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[],System.Security.Policy.Evidence)
  at MonoServiceRunner.Main (System.String[] args) [0x00000]


Expected Results:
Running well

How often does this happen? 
always

Additional Information:
bug related to #76757



---- Additional Comments From robertj@gmx.net 2006-08-29 12:26:47 MST ----

That's rather a bug in mono-service.exe itself.

It assumes that the service is being able to load
mono-service.exe.

That's not possible any more after the "big appdomain fix".

Hotfix: copy mono-service.exe into the service's
current directory.

Long term fix: outsource MonoServiceRunner onto an Assembly
that gets installed into the GC.




---- Additional Comments From miguel@ximian.com 2006-08-29 14:18:32 MST ----

Am trying with this:

using System.ServiceProcess;
using System;

class X :ServiceBase{
        static void Main ()
        {
                Console.WriteLine ("Hello!");
                System.ServiceProcess.ServiceBase.Run (new X());
        }

         protected override void OnStart(string[] args)
        {
                Console.WriteLine ("Startin");
        }
}

I compile this, and then type:

mono-service a.exe

And I do get the message on the console, and the syslog:
Aug 29 13:18:46 erandi mono: /tmp/a.exe: Service  started

I tried moving a.exe to another directory, and it still works:

mono-service /tmp/a.exe






---- Additional Comments From informatique.internet@fiducial.fr 2006-08-30 04:24:08 MST ----

I've compiled your example using :
 mcs service.cs  -r:System.ServiceProcess

I run mono-service ./service.exe

Nothing append (no /tmp/service.exe.lock no message in syslog)

If i run  /usr/lib/mono/1.0/mono-service.exe ./service.exe
i get :
Unhandled Exception: System.IO.FileNotFoundException: mono-service,
Version=0.0.0.0, Culture=neutral : mono-service, Version=0.0.0.0,
Culture=neutral
  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap
(string,string,bool,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[],System.Security.Policy.Evidence)
  at (wrapper remoting-invoke-with-check)
System.AppDomain:CreateInstanceAndUnwrap
(string,string,bool,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo,object[],System.Security.Policy.Evidence)
  at MonoServiceRunner.Main (System.String[] args) [0x00000]

If i copy mono-service.exe to the same directory of ./service.exe it
works well!

Miguel have you tried with svn version?



---- Additional Comments From informatique.internet@fiducial.fr 2006-08-30 05:39:09 MST ----

I think i've a "long term fix" for this problem...
- I've signed mono-service.exe with a strong name
- i've inserted it into the gac (with gacutil -i mono-service.exe)
- I've made a symbolic link in /usr/lib/mono/1.0

and now when i call :
/usr/lib/mono/1.0/mono-service.exe ./service.exe

it works well...

in fact, I've made the same changes in mono-service as in xsp (xsp is
now installed in the gac)




---- Additional Comments From informatique.internet@fiducial.fr 2006-08-30 05:39:55 MST ----

Created an attachment (id=170343)
mono-service.exe (with a strong name) (in order to insert it into the gac)




---- Additional Comments From brian@fluggo.com 2006-08-30 12:19:03 MST ----

Potential alternate solution:

According to the assembly-loading rules, it should be possible to just
strong-name the assembly, but leave it where it is instead of
installing it to the GAC. All you'd have to do is insert a:

<configuration>
  <runtime>
    <assemblyBinding  
   xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705">
      <dependentAssembly>
        <assemblyIdentity name="mono-service.exe" ... />
        <codeBase href="file:///usr..." ... />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

...into machine.config.



---- Additional Comments From robertj@gmx.net 2006-08-30 13:11:00 MST ----

Miguel, try this on your machine. If it works, you definitely
don't run the mono version with the applied appdom patch.


using System;
using System.Reflection;

class Server : MarshalByRefObject
{
        static void Main ()
        {
                AppDomainSetup setup = new AppDomainSetup ();
                setup.ApplicationBase = "bin";

                AppDomain ad = AppDomain.CreateDomain ("foo", null,
setup);
                ad.DoCallBack (new CrossAppDomainDelegate (CallBack));
        }

        static void CallBack ()
        {
        }
}




---- Additional Comments From cjcollier@colliertech.org 2006-08-30 13:52:27 MST ----

updated to r64564

looks like no output goes to /var/log/syslog when using this version



---- Additional Comments From robertj@gmx.net 2006-08-30 16:01:18 MST ----

Created an attachment (id=170344)
mono-service.diff




---- Additional Comments From robertj@gmx.net 2006-08-30 16:06:51 MST ----

The patch adds the necessary support to be able to install
mono-service.exe into the GAC.

It also enables the NET_2_0 build of the program, which is 
missing. The mono-service2 script already exists, though.




---- Additional Comments From robertj@gmx.net 2006-08-30 16:08:02 MST ----

Created an attachment (id=170345)
mono-service2.diff




---- Additional Comments From robertj@gmx.net 2006-08-30 16:08:45 MST ----

Sorry, I attached the wrong patch.

mono-service2.diff is the correct one.




---- Additional Comments From miguel@ximian.com 2006-08-30 19:44:56 MST ----

Applied the patch.



---- Additional Comments From informatique.internet@fiducial.fr 2006-08-31 04:49:56 MST ----

Ok it works well for me now! i close the bug!

Imported an attachment (id=170343)
Imported an attachment (id=170344)
Imported an attachment (id=170345)

Unknown operating system unknown. Setting to default OS "Other".