/// <summary> /// Creates an instance of an object within a host. /// </summary> /// <param name="host">The host in which to create the object.</param> /// <param name="type">The type of object to create.</param> /// <returns>The object instance.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="host" /> /// or <paramref name="type"/> is null.</exception> public static object CreateInstance(IHost host, Type type) { if (type == null) { throw new ArgumentNullException("type"); } // FIXME: Will need to take into account times when we might wish to redirect // the assembly loading to a different path, eg. when DevelopmentRuntimePath // is set. Assembly assembly = type.Assembly; IHostService hostService = host.GetHostService(); try { return(hostService.CreateInstance(assembly.FullName, type.FullName).Unwrap()); } catch (Exception) { return(hostService.CreateInstanceFrom(AssemblyUtils.GetAssemblyLocalPath(assembly), type.FullName).Unwrap()); } }