diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index db44580208..d050fbf10c 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Hosting catch (Exception ex) { var logger = loggerFactory.Create(); - logger.WriteError("TODO: Dispose threw an exception", ex); + logger.WriteError("Dispose threw an exception.", ex); } shutdownHandle.Set(); }); diff --git a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs index a11f8011e5..fd7c9a41ea 100644 --- a/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Server/ServerLoader.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Hosting.Server var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly == null) { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", assemblyName)); + throw new Exception(string.Format("The assembly {0} failed to load.", assemblyName)); } Type type = null; @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Hosting.Server if (type == null) { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + throw new Exception(string.Format("The type {0} failed to load.", typeName ?? "")); } } else @@ -59,14 +59,14 @@ namespace Microsoft.AspNet.Hosting.Server if (type == null) { - throw new Exception(String.Format("TODO: type {0} failed to load message", typeName ?? "")); + throw new Exception(String.Format("The type {0} failed to load.", typeName ?? "")); } interfaceInfo = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(interf => interf.Equals(typeof(IServerFactory))); if (interfaceInfo == null) { - throw new Exception("TODO: IServerFactory interface not found"); + throw new Exception(string.Format("The type '{0}' does not implement the '{1}' interface.", type, typeof(IServerFactory).FullName)); } } diff --git a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs index 165e5a7da4..ba6c013f12 100644 --- a/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs +++ b/src/Microsoft.AspNet.Hosting/Startup/StartupLoader.cs @@ -31,9 +31,10 @@ namespace Microsoft.AspNet.Hosting.Startup { if (required) { - throw new Exception(string.Format("TODO: {0} or {1} method not found", + throw new Exception(string.Format("A method named '{0}' or '{1}' in the type '{2}' could not be found.", methodNameWithEnv, - methodNameWithNoEnv)); + methodNameWithNoEnv, + startupType.FullName)); } return null; @@ -42,8 +43,10 @@ namespace Microsoft.AspNet.Hosting.Startup { if (required) { - throw new Exception(string.Format("TODO: {0} method does not return " + returnType.Name, - methodInfo.Name)); + throw new Exception(string.Format("The '{0}' method in the type '{1}' must have a return type of '{2}'.", + methodInfo.Name, + startupType.FullName, + returnType.Name)); } return null; } @@ -75,10 +78,11 @@ namespace Microsoft.AspNet.Hosting.Startup catch (Exception) { throw new Exception(string.Format( - "TODO: Unable to resolve service for {0} method {1} {2}", - methodInfo.Name, + "Could not resolve a service of type '{0}' for the parameter '{1}' of method '{2}' on type '{3}'.", + parameterInfo.ParameterType.FullName, parameterInfo.Name, - parameterInfo.ParameterType.FullName)); + methodInfo.Name, + methodInfo.DeclaringType.FullName)); } } } @@ -98,26 +102,26 @@ namespace Microsoft.AspNet.Hosting.Startup var assembly = Assembly.Load(new AssemblyName(applicationName)); if (assembly == null) { - throw new Exception(String.Format("TODO: assembly {0} failed to load message", applicationName)); + throw new Exception(String.Format("The assembly '{0}' failed to load.", applicationName)); } - var startupName1 = "Startup" + environmentName; - var startupName2 = "Startup"; + var startupNameWithEnv = "Startup" + environmentName; + var startupNameWithoutEnv = "Startup"; // Check the most likely places first var type = - assembly.GetType(startupName1) ?? - assembly.GetType(applicationName + "." + startupName1) ?? - assembly.GetType(startupName2) ?? - assembly.GetType(applicationName + "." + startupName2); + assembly.GetType(startupNameWithEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithEnv) ?? + assembly.GetType(startupNameWithoutEnv) ?? + assembly.GetType(applicationName + "." + startupNameWithoutEnv); if (type == null) { // Full scan var definedTypes = assembly.DefinedTypes.ToList(); - var startupType1 = definedTypes.Where(info => info.Name.Equals(startupName1, StringComparison.Ordinal)); - var startupType2 = definedTypes.Where(info => info.Name.Equals(startupName2, StringComparison.Ordinal)); + var startupType1 = definedTypes.Where(info => info.Name.Equals(startupNameWithEnv, StringComparison.Ordinal)); + var startupType2 = definedTypes.Where(info => info.Name.Equals(startupNameWithoutEnv, StringComparison.Ordinal)); var typeInfo = startupType1.Concat(startupType2).FirstOrDefault(); if (typeInfo != null) @@ -128,9 +132,9 @@ namespace Microsoft.AspNet.Hosting.Startup if (type == null) { - throw new Exception(String.Format("TODO: {0} or {1} class not found in assembly {2}", - startupName1, - startupName2, + throw new Exception(String.Format("A type named '{0}' or '{1}' could not be found in assembly '{2}'.", + startupNameWithEnv, + startupNameWithoutEnv, applicationName)); } diff --git a/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs new file mode 100644 index 0000000000..8679e62093 --- /dev/null +++ b/test/Microsoft.AspNet.Hosting.Tests/Fakes/StartupWithConfigureServicesNotResolved.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Builder; + +namespace Microsoft.AspNet.Hosting.Fakes +{ + public class StartupWithConfigureServicesNotResolved + { + public StartupWithConfigureServicesNotResolved() + { + } + + public void Configure(IApplicationBuilder builder, int notAService) + { + } + } +} diff --git a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs index 188333960a..db19ddc403 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/StartupManagerTests.cs @@ -114,7 +114,25 @@ namespace Microsoft.AspNet.Hosting.Tests var diagnosticMessages = new List(); var ex = Assert.Throws(() => loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "Boom", diagnosticMessages)); - Assert.True(ex.Message.Contains("ConfigureBoom or Configure method not found")); + Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message); + } + + [Fact] + public void StartupWithConfigureServicesNotResolvedThrows() + { + var serviceCollection = HostingServices.Create(); + var services = serviceCollection.BuildServiceProvider(); + var loader = services.GetRequiredService(); + var diagnosticMessages = new List(); + + var startup = loader.LoadStartup("Microsoft.AspNet.Hosting.Tests", "WithConfigureServicesNotResolved", diagnosticMessages); + + + var app = new ApplicationBuilder(services); + + var ex = Assert.Throws(() => startup.Invoke(app)); + + Assert.Equal("Could not resolve a service of type 'System.Int32' for the parameter 'notAService' of method 'Configure' on type 'Microsoft.AspNet.Hosting.Fakes.StartupWithConfigureServicesNotResolved'.", ex.Message); } [Fact]