[Mono-list] Assembly.Load Behavior difference, AssemblyName.FullName different

Emiel van de Laar emiel@il.fontys.nl
Fri, 04 Jun 2004 13:32:54 +0200


This is a multi-part message in MIME format.
--------------000809070804050001050709
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

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.

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

e.vandelaar@magion-38 /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

--------------000809070804050001050709
Content-Type: text/plain;
 name="dotnet-on-ms.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="dotnet-on-ms.txt"

e.vandelaar@magion-38 /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");
    }
  }
}


e.vandelaar@magion-38 /cygdrive/c/cruft
$ csc /nologo /t:library plugin.cs

e.vandelaar@magion-38 /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();
    }
  }
}


e.vandelaar@magion-38 /cygdrive/c/cruft
$ csc /nologo app.cs

e.vandelaar@magion-38 /cygdrive/c/cruft
$ ./app.exe
FullName: "plugin"
New Duck


--------------000809070804050001050709
Content-Type: text/plain;
 name="mono-on-linux.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mono-on-linux.txt"

emiel@marvin:~/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");
    }
  }
}

emiel@marvin:~/csharp/ass> mcs -t:library plugin.cs
Compilation succeeded
emiel@marvin:~/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();
    }
  }
}

emiel@marvin:~/csharp/ass> mcs app.cs
Compilation succeeded
emiel@marvin:~/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 ()


--------------000809070804050001050709--