AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly2";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly3";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath ());
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly4";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly5";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly6";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly7";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly8";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly9";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
}
}
-#if NET_2_0
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
public void DefineDynamicAssembly10_Access_Invalid ()
{
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly10";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true,
- new List<CustomAttributeBuilder> ());
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
AssemblyName name = new AssemblyName ();
name.Name = "DefineDynamicAssembly11";
-#if NET_2_0
try {
AppDomain.CurrentDomain.DefineDynamicAssembly (
name, AssemblyBuilderAccess.Run |
Assert.IsNotNull (ex.ParamName, "#6");
Assert.AreEqual ("access", ex.ParamName, "#7");
}
-#else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- new List<CustomAttributeBuilder> ());
- Assert.IsNotNull (ab, "#1");
-#endif
}
[Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
}
}
-#endif
[Test]
public void SetThreadPrincipal ()
AppDomain.CurrentDomain.ExecuteAssembly (
assembly.Location);
Assert.Fail ("#1");
-#if NET_2_0
} catch (MissingMethodException ex) {
// Entry point not found in assembly '...'
Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
}
-#else
- } catch (COMException ex) {
- // Unspecified error
- Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
- Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- }
-#endif
}
[Test] // ExecuteAssembly (String, Evidence)
assembly.Location,
(Evidence) null);
Assert.Fail ("#1");
-#if NET_2_0
} catch (MissingMethodException ex) {
// Entry point not found in assembly '...'
Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
}
-#else
- } catch (COMException ex) {
- // Unspecified error
- Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
- Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- }
-#endif
}
[Test] // ExecuteAssembly (String, Evidence, String [])
(Evidence) null,
new string [0]);
Assert.Fail ("#1");
-#if NET_2_0
} catch (MissingMethodException ex) {
// Entry point not found in assembly '...'
Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
}
-#else
- } catch (COMException ex) {
- // Unspecified error
- Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
- Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- }
-#endif
}
[Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
(byte []) null,
AssemblyHashAlgorithm.SHA1);
Assert.Fail ("#1");
-#if NET_2_0
} catch (MissingMethodException ex) {
// Entry point not found in assembly '...'
Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
}
-#else
- } catch (COMException ex) {
- // Unspecified error
- Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
- Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
- Assert.IsNull (ex.InnerException, "#4");
- Assert.IsNotNull (ex.Message, "#5");
- }
-#endif
}
[Test] // bug #79720
aname = new AssemblyName ();
aname.Name = "bug79522A";
aname.CodeBase = assemblyFile;
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#A3");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522A";
aname.CodeBase = assemblyFile;
aname.Version = new Version (2, 5);
-#if NET_2_0
// the version number is not considered when comparing the manifest
// of the assembly found using codebase
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#A4");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522A";
aname.CodeBase = assemblyFile;
aname.Version = new Version (2, 4, 1);
-#if NET_2_0
// the version number is not considered when comparing the manifest
// of the assembly found using codebase
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#A5");
- } catch (FileLoadException) {
- }
-#endif
// if version is set, then culture must also be set
aname = new AssemblyName ();
aname.Name = "bug79522A";
aname.CodeBase = assemblyFile;
aname.Version = new Version (2, 4);
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#A6");
- } catch (FileLoadException) {
- }
-#endif
// version number does not need to be set
aname = new AssemblyName ();
aname = new AssemblyName ();
aname.Name = "bug79522B";
aname.CodeBase = assemblyFile;
-#if NET_2_0
// the version number is not considered when comparing the manifest
// of the assembly found using codebase
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#B3");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522B";
aname.CodeBase = assemblyFile;
aname.Version = new Version (5, 5);
-#if NET_2_0
// the version number is not considered when comparing the manifest
// of the assembly found using codebase
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#B3");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522B";
aname.CodeBase = assemblyFile;
aname.Version = new Version (2, 4, 1);
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- // when the loaded assembly has a specific culture, then that
- // culture must be set if you set the Version on the aname
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#B4");
- } catch (FileLoadException) {
- }
-#endif
// version does not need to be set
aname = new AssemblyName ();
aname = new AssemblyName ();
aname.Name = "bug79522C";
aname.CodeBase = assemblyFile;
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#C3");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522C";
aname.Name = "bug79522C";
aname.CodeBase = assemblyFile;
aname.Version = new Version (2, 4);
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- // when the loaded assembly has a specific culture/publickey,
- // then that culture/publickey must be set if you set the
- // Version on the aname
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#C4");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522C";
aname.CodeBase = assemblyFile;
aname.CultureInfo = new CultureInfo ("nl-BE");
aname.Version = new Version (2, 4);
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- // if loaded assembly is signed, then the public key must be set
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#C5");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522C";
aname.CodeBase = assemblyFile;
aname.CultureInfo = new CultureInfo ("nl-BE");
aname.SetPublicKey (publicKey);
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- // if public key is set, then version must be set
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#C6");
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522C";
aname.CodeBase = assemblyFile;
aname.CultureInfo = new CultureInfo ("nl-BE");
-#if NET_2_0
AppDomain.CurrentDomain.Load (aname);
-#else
- try {
- AppDomain.CurrentDomain.Load (aname);
- Assert.Fail ("#C7");
- } catch (FileLoadException) {
- }
-#endif
// if culture and version are set, then the version must match
aname = new AssemblyName ();
try {
AppDomain.CurrentDomain.Load (aname);
Assert.Fail ("#C9");
-#if NET_2_0
} catch (SecurityException) {
// Invalid assembly public key
}
-#else
- } catch (FileLoadException) {
- }
-#endif
aname = new AssemblyName ();
aname.Name = "bug79522C";
AppDomain.CurrentDomain.SetData (null, "data");
}
-#if NET_2_0
[Test]
public void ApplyPolicy ()
{
// we have no public way to get the default appdomain
}
+ static bool resolve_called;
+
+ [Test]
+ public void AssemblyResolveParseError ()
+ {
+ AppDomain currentDomain = AppDomain.CurrentDomain;
+ ResolveEventHandler d = ParseErrorResolve;
+ currentDomain.AssemblyResolve += d;
+ try {
+ resolve_called = false;
+ var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
+ Assert.Fail ();
+ } catch (FileNotFoundException) {
+ Assert.IsTrue (resolve_called);
+ }
+ currentDomain.AssemblyResolve -= d;
+ }
+
+ static Assembly ParseErrorResolve (object sender, ResolveEventArgs args)
+ {
+ resolve_called = true;
+ return null;
+ }
+
[Test]
public void ReflectionOnlyGetAssemblies ()
{
{
return Assembly.ReflectionOnlyLoad(args.Name);
}
-#endif
+
public class StuffToPick
{
public event Action Event;
public int Field;
public void GenericMethod<T> () {}
+
+ public void Dummy ()
+ {
+ Event += delegate {};
+ }
}
public class StuffToPick<T>
public int Property { get; set; }
public event Action Event;
public int Field;
- public void GenericMethod<T> () {}
+ public void GenericMethod<U> () {}
+
+ public void Dummy ()
+ {
+ Event += delegate {};
+ }
}
static void TestSerialization (CrossDomainTester tester, object o)
}
[Test] //BXC #12611
- [Category ("NotWorking")] // Serialization can't handle generic methods
public void GenericReflectionObjectsAreSerializableTest ()
{
ad = CreateTestDomain (tempDir, true);
TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
}
+ [Test]
+ public void ShadowCopyTypeGetTypeMissingAssemblyTest ()
+ {
+ ad = CreateShadowCopyAppDomain (tempDir, true);
+ CrossDomainTester tester = CreateCrossDomainTester (ad);
+ tester.AssertLoadMissingAssemblyType ();
+ }
+
+ [Test]
+ public void ShadowCopyDontChangeAssemblyCodeBase ()
+ {
+ var setup = new AppDomainSetup ();
+ setup.ApplicationBase = tempDir;
+ setup.ApplicationName = "testdomain";
+ setup.ShadowCopyFiles = "true";
+ var ad = CreateTestDomain (setup, true);
+
+ string assemblyFile = Path.Combine (tempDir, "TestAssembly.dll");
+ AssemblyName aname = new AssemblyName ();
+ aname.Name = "TestAssembly";
+ GenerateAssembly (aname, assemblyFile);
+
+ var tester = CreateCrossDomainTester (ad);
+ var codeBaseFromShadowCopy = tester.LoadAndGetName ("TestAssembly");
+ var expected = Assembly.LoadFrom (Path.Combine (tempDir, "TestAssembly.dll"));
+ Assert.AreEqual (expected.GetName ().CodeBase, codeBaseFromShadowCopy);
+ }
+
private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
{
AppDomainSetup setup = new AppDomainSetup ();
return CreateTestDomain (setup, assemblyResolver);
}
+ private static AppDomain CreateShadowCopyAppDomain (string baseDirectory, bool assemblyResolver)
+ {
+ AppDomainSetup setup = new AppDomainSetup ();
+ setup.ApplicationBase = baseDirectory;
+ setup.ApplicationName = "testdomain";
+ setup.ShadowCopyFiles = "true";
+ return CreateTestDomain (setup, assemblyResolver);
+ }
+
private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
{
AppDomain ad = AppDomain.CreateDomain ("testdomain",
}
}
- public bool AssertFileLoadException (AssemblyName assemblyRef)
+ public void AssertLoadMissingAssemblyType ()
{
- try {
- AppDomain.CurrentDomain.Load (assemblyRef);
- return false;
- } catch (FileLoadException) {
- return true;
- }
+ Assert.IsNull (Type.GetType ("A.B.C, MissingAssembly"));
}
- public bool AssertFileNotFoundException (AssemblyName assemblyRef)
+ public bool AssertFileLoadException (AssemblyName assemblyRef)
{
try {
AppDomain.CurrentDomain.Load (assemblyRef);
return false;
- } catch (FileNotFoundException) {
+ } catch (FileLoadException) {
return true;
}
}
{
return obj;
}
+
+ public string LoadAndGetName (string assemblyName)
+ {
+ var assembly = Assembly.Load (assemblyName);
+ return assembly.GetName ().CodeBase;
+ }
}
[Serializable ()]
}
}
-#endif
\ No newline at end of file
+#endif