Do not throw a NullReferenceException when Host variable is not set.
Ignore the calls to RegisterObject and UnregisterObject instead.
{
if (obj == null)
throw new ArgumentNullException ("obj");
- Host.RegisterObject (obj, false);
+
+ if (Host != null)
+ Host.RegisterObject (obj, false);
}
public static void RegisterVirtualPathProvider (VirtualPathProvider virtualPathProvider)
{
if (obj == null)
throw new ArgumentNullException ("obj");
- Host.UnregisterObject (obj);
+
+ if (Host != null)
+ Host.UnregisterObject (obj);
}
}
}
using MonoTests.SystemWeb.Framework;
namespace MonoTests.System.Web.Hosting {
+ public class MyRegisteredObject : IRegisteredObject {
+ public void Stop(bool immediate) {}
+ }
+
[TestFixture]
public class HostingEnvironmentTest {
[Test]
{
Assert.IsNull (HostingEnvironment.MapPath ("hola"));
}
+
+ [Test]
+ public void RegisterAndUnregisterObject ()
+ {
+ var registered = new MyRegisteredObject ();
+
+ HostingEnvironment.RegisterObject (registered);
+ HostingEnvironment.UnregisterObject (registered);
+ }
}
}
#endif