using System.Runtime.Serialization;
using System.Security;
using System.Linq;
+using System.Resources;
namespace MonoTests.System.Reflection
{
// note: only available in default appdomain
// http://weblogs.asp.net/asanto/archive/2003/09/08/26710.aspx
// Not sure we should emulate this behavior.
+#if !MONODROID
string fname = AppDomain.CurrentDomain.FriendlyName;
if (fname.EndsWith (".dll")) { // nunit-console
Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
Assert.IsNotNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
}
+#else
+ Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
+ Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
+#endif
}
#if !MONOTOUCH // Reflection.Emit is not supported.
[Test]
+ [Category("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter
public void GetModules_MissingFile ()
{
AssemblyName newName = new AssemblyName ();
public void Corlib_test ()
{
Assembly corlib_test = Assembly.GetExecutingAssembly ();
-#if MOBILE
+#if MONODROID
+ Assert.IsNull (corlib_test.EntryPoint, "EntryPoint");
+ Assert.IsNull (corlib_test.Evidence, "Evidence");
+#elif MOBILE
Assert.IsNotNull (corlib_test.EntryPoint, "EntryPoint");
Assert.IsNull (corlib_test.Evidence, "Evidence");
#else
Assert.IsTrue (corlib_test.GetReferencedAssemblies ().Length > 0, "GetReferencedAssemblies");
Assert.AreEqual (0, corlib_test.HostContext, "HostContext");
-#if NET_4_0 && !MOBILE
Assert.AreEqual ("v4.0.30319", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
-#else
- Assert.AreEqual ("v2.0.50727", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
-#endif
Assert.IsNotNull (corlib_test.ManifestModule, "ManifestModule");
Assert.IsFalse (corlib_test.ReflectionOnly, "ReflectionOnly");
}
[Test]
+ [Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be accessed as FileStream
public void GetFiles_False ()
{
Assembly corlib = typeof (int).Assembly;
}
[Test]
+ [Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be accessed as FileStream
public void GetFiles_True ()
{
Assembly corlib = typeof (int).Assembly;
}
}
+ [Test]
+ public void SateliteAssemblyForInMemoryAssembly ()
+ {
+ string assemblyFileName = Path.Combine (
+ Path.GetTempPath (), "AssemblyLocation1.dll");
+
+ try {
+ AssemblyName assemblyName = new AssemblyName ();
+ assemblyName.Name = "AssemblyLocation1";
+
+ AssemblyBuilder ab = AppDomain.CurrentDomain
+ .DefineDynamicAssembly (assemblyName,
+ AssemblyBuilderAccess.Save,
+ Path.GetTempPath ());
+
+ ModuleBuilder moduleBuilder = ab.DefineDynamicModule (assemblyName.Name, assemblyName.Name + ".dll");
+ TypeBuilder typeBuilder = moduleBuilder.DefineType ("Program", TypeAttributes.Public);
+
+ MethodBuilder methodBuilder = typeBuilder.DefineMethod ("TestCall", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Type.EmptyTypes);
+ ILGenerator gen = methodBuilder.GetILGenerator ();
+
+ //
+ // var resourceManager = new ResourceManager (typeof (Program));
+ // resourceManager.GetString ("test");
+ //
+ gen.Emit (OpCodes.Ldtoken, typeBuilder);
+ gen.Emit (OpCodes.Call, typeof(Type).GetMethod ("GetTypeFromHandle"));
+ gen.Emit (OpCodes.Newobj, typeof(ResourceManager).GetConstructor (new Type[] { typeof(Type) }));
+ gen.Emit (OpCodes.Ldstr, "test");
+ gen.Emit (OpCodes.Callvirt, typeof(ResourceManager).GetMethod ("GetString", new Type[] { typeof(string) }));
+ gen.Emit (OpCodes.Pop);
+ gen.Emit (OpCodes.Ret);
+
+ typeBuilder.CreateType ();
+
+ ab.Save (Path.GetFileName (assemblyFileName));
+
+ using (FileStream fs = File.OpenRead (assemblyFileName)) {
+ byte[] buffer = new byte[fs.Length];
+ fs.Read (buffer, 0, buffer.Length);
+ Assembly assembly = Assembly.Load (buffer);
+
+ var mm = assembly.GetType ("Program").GetMethod ("TestCall");
+ try {
+ mm.Invoke (null, null);
+ Assert.Fail ();
+ } catch (TargetInvocationException e) {
+ Assert.IsTrue (e.InnerException is MissingManifestResourceException);
+ }
+
+ fs.Close ();
+ }
+ } finally {
+ File.Delete (assemblyFileName);
+ }
+ }
+
[Test]
[Category ("NotWorking")]
public void bug78464 ()
}
[Test]
+ [Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be directly as files
public void ReflectionOnlyLoadFrom ()
{
string loc = typeof (AssemblyTest).Assembly.Location;