Hi all,

I was playing around with Assembly.Load and noticed a couple of diffences in behaviour.

First the Assembly.FullName property emits different strings on Mono and MS .NET. Mono emits the full four-part name (name, version, culture, public key). Even if these values are not specified, default values are emitted. On the MS .NET platform only the parts specified are emitted.
I've yet to look what the spec says about this; perhaps both are permitted.


The two sessions attached to this mail show that using Assembly.Load fails on Mono but works on MS .NET. I'm not sure if the Assembly.FullName property has anything to with it.

BTW. Here some version info... I have not yet been able to try
Mono Beta 2.

[EMAIL PROTECTED]:~/csharp/ass> mono --version
Mono JIT compiler version 0.30.2, (C) 2002-2004 Novell, Inc. www.go-mono.com
[EMAIL PROTECTED]:~/csharp/ass> mcs --version
Mono C# compiler version 0.29.99.0

[EMAIL PROTECTED] /cygdrive/c/cruft
$ csc
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

Cheers,

Emiel
--
Emiel van de Laar
[EMAIL PROTECTED] /cygdrive/c/cruft
$ expand -t2 plugin.cs
using System;

namespace EvilZoo
{
  public class Duck
  {
    public Duck()
    {
      Console.WriteLine("New Duck");
    }

    public void Speak()
    {
      Console.WriteLine("Quack");
    }
  }
}


[EMAIL PROTECTED] /cygdrive/c/cruft
$ csc /nologo /t:library plugin.cs

[EMAIL PROTECTED] /cygdrive/c/cruft
$ expand -t2 app.cs
using System;
using System.IO;
using System.Reflection;

namespace EvilZoo
{
  class App
  {
    public App()
    {
      AssemblyName plugin = new AssemblyName();

      plugin.Name = "plugin";
      plugin.CodeBase = String.Concat("file:///", Directory.GetCurrentDirectory());

      Console.WriteLine("FullName: \"{0}\"", plugin.FullName);

      Assembly asm = Assembly.Load(plugin);

      object foo = asm.CreateInstance("EvilZoo.Duck");
    }

    static void Main()
    {
      new App();
    }
  }
}


[EMAIL PROTECTED] /cygdrive/c/cruft
$ csc /nologo app.cs

[EMAIL PROTECTED] /cygdrive/c/cruft
$ ./app.exe
FullName: "plugin"
New Duck

[EMAIL PROTECTED]:~/csharp/ass> expand -t2 plugin.cs
using System;

namespace EvilZoo
{
  public class Duck
  {
    public Duck()
    {
      Console.WriteLine("New Duck");
    }

    public void Speak()
    {
      Console.WriteLine("Quack");
    }
  }
}

[EMAIL PROTECTED]:~/csharp/ass> mcs -t:library plugin.cs
Compilation succeeded
[EMAIL PROTECTED]:~/csharp/ass> expand -t2 app.cs
using System;
using System.IO;
using System.Reflection;

namespace EvilZoo
{
  class App
  {
    public App()
    {
      AssemblyName plugin = new AssemblyName();

      plugin.Name = "plugin";
      plugin.CodeBase = String.Concat("file:///", Directory.GetCurrentDirectory());

      Console.WriteLine("FullName: \"{0}\"", plugin.FullName);

      Assembly asm = Assembly.Load(plugin);

      object foo = asm.CreateInstance("EvilZoo.Duck");
    }

    static void Main()
    {
      new App();
    }
  }
}

[EMAIL PROTECTED]:~/csharp/ass> mcs app.cs
Compilation succeeded
[EMAIL PROTECTED]:~/csharp/ass> ./app.exe
FullName: "plugin, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"

Unhandled Exception: System.IO.FileNotFoundException: File 'plugin, Version=0.0.0.0, 
Culture=neutral, PublicKeyToken=null' not found.
in (unmanaged) /usr/lib/libmono.so.0(mono_raise_exception+0x1f) [0x4009abbf]
in (unmanaged) /usr/lib/libmono.so.0 [0x400c0387]
in <0x0002e> (wrapper managed-to-native) System.AppDomain:LoadAssembly 
(string,System.Security.Policy.Evidence)
in <0x0006b> (wrapper remoting-invoke-with-check) System.AppDomain:LoadAssembly 
(string,System.Security.Policy.Evidence)
in <0x0005e> System.AppDomain:Load 
(System.Reflection.AssemblyName,System.Security.Policy.Evidence)
in <0x0006b> (wrapper remoting-invoke-with-check) System.AppDomain:Load 
(System.Reflection.AssemblyName,System.Security.Policy.Evidence)
in <0x0003d> System.AppDomain:Load (System.Reflection.AssemblyName)
in <0x00058> (wrapper remoting-invoke-with-check) System.AppDomain:Load 
(System.Reflection.AssemblyName)
in <0x0001c> System.Reflection.Assembly:Load (System.Reflection.AssemblyName)
in <0x000af> EvilZoo.App:.ctor ()
in <0x0001e> EvilZoo.App:Main ()

Reply via email to