Inheritance: SystemException, ISerializable
Example #1
0
        /// <summary>
        /// Searches the passed Path for Plugins
        /// </summary>
        /// <param name="Path">Directory to search for Plugins in</param>
        public void Load(string Path, string pattern)
        {
            //First empty the collection, we're reloading them all
            mAvailablePlugins.Clear();

            try
            {
                //Go through all the files in the plugin directory
                foreach (string fileOn in Directory.GetFiles(Path, pattern))
                {
                    FileInfo file = new FileInfo(fileOn);

                    //Preliminary check, must be .dll
                    if (file.Extension.Equals(".dll"))
                    {
                        //Add the 'plugin'
                        this.AddPlugin(fileOn);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Reflection.ReflectionTypeLoadException e = ex as System.Reflection.ReflectionTypeLoadException;
                if (e != null)
                {
                    foreach (Exception ee in e.LoaderExceptions)
                    {
                        Console.WriteLine(ee.Message);
                    }
                }
            }
        }
Example #2
0
        public static void TraceException(System.Exception exception)
        {
            if (exception == null)
            {
                WriteLine("Exception is null");
                return;
            }

            WriteLine("Unhandled exception : " + exception.GetType().FullName + "\n" +
                      "Message : " + exception.Message + "\n" +
                      "Stack Trace \n" + exception.StackTrace + "\n" +
                      "Source : " + exception.Source + "\n" +
                      "TargetSite : " + exception.TargetSite + "\n"
                      );
            if (exception.InnerException != null)
            {
                WriteLine("Inner Exception");
                TraceException(exception.InnerException);
            }

            System.Reflection.ReflectionTypeLoadException tle = exception as System.Reflection.ReflectionTypeLoadException;
            System.Security.SecurityException             se  = exception as System.Security.SecurityException;
            if (tle != null)
            {
                WriteLine("Loader Exceptions");

                foreach (Exception tlle in tle.LoaderExceptions)
                {
                    WriteLine("Loader Exception:");
                    TraceException(tlle);
                }
            }
            else if (se != null)
            {
                WriteLine("Security Exception");
                WriteLine("Action : " + se.Action);

                WriteLine("PermissionType    : " + se.PermissionType);
            }


            StackTrace st = new StackTrace(true);

            WriteLine("Current Stack" + st.ToString());

            WriteLine("\r\nAssemblies:");
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                WriteLine("Name : " + asm.FullName);
                try
                {
                    WriteLine("\tPath:" + asm.Location);
                }
                catch
                {
                }
            }
        }
 protected virtual void HandlePluginLoadReflectionException(PluginData data, ReflectionTypeLoadException ex)
 {
     String err = "Error creating plugin from dll \"" + data.dll + "\" due to a loader exception error was:\n";
     foreach (Exception e in ex.LoaderExceptions)
         err += e.Message + "\n";
     data.last_error = err;
     data.state = PluginData.PluginDataState.ERROR_LOADING;
     Utils.PluginLog(PluginManagerName(), err);
 }
        Tuple<string, bool> HandleReflectionTypeLoadException(ReflectionTypeLoadException e,
            ReportExceptionEventArgs et) {
            Tuple<string, bool> handled = null;
            foreach (var error in e.LoaderExceptions) {
                if (handled == null || handled.Item1 == null)
                    handled = InternalHandler(error, et, true);
            }

            return handled;
        }
        public static void ThrowReflectionTypeLoadException(ReflectionTypeLoadException tLException)
        {
            var loaderMessages = new StringBuilder();
            loaderMessages.AppendLine("While trying to load composable parts the following loader exceptions were found: ");
            foreach (var loaderException in tLException.LoaderExceptions)
            {
                loaderMessages.AppendLine(loaderException.Message);
            }

            throw new Exception(loaderMessages.ToString(), tLException);
        }
Example #6
0
 static string FormatLoaderExceptionMessage(Assembly assembly, ReflectionTypeLoadException e)
 {
     //http://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes
     StringBuilder message = new StringBuilder();
     message.AppendLine(string.Format("{0} assembly LoaderException messages:", assembly.FullName));
     foreach (Exception loaderException in e.LoaderExceptions)
     {
         if (loaderException == null) continue;
         message.AppendLine(loaderException.Message);
     }
     return message.ToString();
 }
Example #7
0
		private static string GetLoaderExceptions(ReflectionTypeLoadException exception)
		{
			var sb = new StringBuilder();
			sb.AppendLine(exception.ToString());
			foreach (var loaderException in exception.LoaderExceptions)
			{
				sb.AppendLine("- - - -").AppendLine();
				sb.AppendLine(loaderException.ToString());
			}

			return sb.ToString();
		}
Example #8
0
        private static string niceMessage(Assembly assembly, ReflectionTypeLoadException exception)
        {
            var result = new StringBuilder();

            result.Append("Failed to load ");
            result.Append(assembly.FullName);
            result.Append(". ");
            result.Append(exception.Message);

            //TODO: add detail

            return result.ToString();
        }
        public void ReflectionTypeLoadExceptionSupport()
        {
            FileNotFoundException ex1 = new FileNotFoundException();
              OutOfMemoryException ex2 = new OutOfMemoryException();
              ReflectionTypeLoadException wrapper = new ReflectionTypeLoadException(new Type[] { typeof(FakeRaygunClient), typeof(WrapperException) }, new Exception[] { ex1, ex2 });

              RaygunErrorMessage message = RaygunErrorMessageBuilder.Build(wrapper);

              Assert.AreEqual(2, message.InnerErrors.Count());
              Assert.AreEqual("System.IO.FileNotFoundException", message.InnerErrors[0].ClassName);
              Assert.AreEqual("System.OutOfMemoryException", message.InnerErrors[1].ClassName);

              Assert.IsTrue(message.InnerErrors[0].Data["Type"].ToString().Contains("FakeRaygunClient"));
              Assert.IsTrue(message.InnerErrors[1].Data["Type"].ToString().Contains("WrapperException"));
        }
Example #10
0
            public override void ShowException(ReflectionTypeLoadException ex)
            {
                var message = "ReflectionTypeLoadException:";
                var types = ex.Types;
                message += Environment.NewLine + "  -------------- ";
                message += Environment.NewLine + "  Types : " +
                           (types == null ? "<null>" : types.Length.ToString(CultureInfo.CurrentUICulture));

                message = AddTypes(message, types);
                message += Environment.NewLine + "  -------------- ";

                message = AddExceptions(message, ex.LoaderExceptions);

                _logger.Trace(message);
            }
		private static string CreateMessage(Assembly loadedAssembly, ReflectionTypeLoadException ex)
		{
			StringBuilder builder = new StringBuilder();
			builder.AppendFormat("Unable to load types from assembly {0}:", loadedAssembly.GetName()).Append(Environment.NewLine);
			builder.AppendFormat("Failed to load {0} of the {1} types defined in the assembly.", ex.LoaderExceptions.Length, ex.Types.Length).Append(Environment.NewLine);
			builder.Append("Exceptions: ").Append(Environment.NewLine);
			foreach (Exception exception in ex.LoaderExceptions)
			{
				TypeLoadException loaderException = exception as TypeLoadException;
				if (loaderException != null)
				{
					builder.AppendFormat("- Unable to load type: {0}", loaderException.TypeName).Append(Environment.NewLine);
				}
				builder.Append("	Exception: ").Append(exception.ToString());
			}
			return builder.ToString();
		}
        public static void HandleReflectionTypeLoadException(ReflectionTypeLoadException rfex)
        {
            string loaderExceptionMessages = "";
            //string msg = "********************* " + helperMessage + "*********************";
            foreach (var t in rfex.LoaderExceptions)
            {
                loaderExceptionMessages += "   -  ";
                loaderExceptionMessages += t.Message;
                loaderExceptionMessages += Environment.NewLine;
            }

            string msg = @"
            ********************* ReflectionTypeLoadException *********************
            ***** Begin Loader Exception Messages *****
            {0}
            ***** End Loader Exception Messages *****
            ".FormatWith(loaderExceptionMessages);

            Server.Trace(msg);
        }
Example #13
0
        private static void PrintTypeLoadError(ReflectionTypeLoadException exc)
        {
            if (exc == null)
                return;
            LogWriteLine("LoaderExceptions:");
            foreach (var e in exc.LoaderExceptions)
            {
                LogWrite("-- ");
                LogWrite(e.GetType().FullName);
                LogWrite(": ");
                LogWriteLine(e.Message);

                var fileNotFoundException = e as FileNotFoundException;
                if (fileNotFoundException != null)
                {
                    LogWriteLine("FUSION LOG:");
                    LogWriteLine(fileNotFoundException.FusionLog);
                }
            }
        }
		public NetReflectorTypeLoadException(Assembly loadedAssembly, ReflectionTypeLoadException ex) : base(CreateMessage(loadedAssembly, ex))
		{
		}
        private static string BuildErrorMessage(ReflectionTypeLoadException exception)
        {
            var builder = new StringBuilder("One or more errors occurred while loading the selected plugin:");
            builder.AppendLine();
            builder.AppendLine();

            foreach (Exception loaderException in exception.LoaderExceptions)
            {
                builder.AppendLine(loaderException.Message);
            }

            return builder.ToString();
        }
Example #16
0
        internal static string FormatReflectionTypeLoadException(string fileName, ReflectionTypeLoadException e)
        {
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("Could not enumerate all types for '{0}'.", fileName));

            if (!e.LoaderExceptions.Any())
            {
                sb.AppendLine(string.Format("Exception message: {0}", e));
                return sb.ToString();
            }

            var nsbAssemblyName = typeof(AssemblyScanner).Assembly.GetName();
            var nsbPublicKeyToken = BitConverter.ToString(nsbAssemblyName.GetPublicKeyToken()).Replace("-", "").ToLowerInvariant();
            var displayBindingRedirects = false;

            var displayHeader = true;
            foreach (var ex in e.LoaderExceptions)
            {
                var loadException = ex as FileLoadException;

                if (loadException != null)
                {
                    var assemblyName = new AssemblyName(loadException.FileName);
                    var assemblyPublicKeyToken = BitConverter.ToString(assemblyName.GetPublicKeyToken()).Replace("-", "").ToLowerInvariant();
                    if (nsbAssemblyName.Name == assemblyName.Name && nsbAssemblyName.CultureInfo.ToString() == assemblyName.CultureInfo.ToString() && nsbPublicKeyToken == assemblyPublicKeyToken)
                    {
                        displayBindingRedirects = true;
                    }
                }
                else
                {
                    if (displayHeader)
                    {
                        sb.AppendLine("Assembly scanner errors:");
                        displayHeader = false;
                    }
                    sb.AppendLine(ex.ToString());
                }
            }

            if (displayBindingRedirects)
            {
                sb.AppendLine();
                sb.AppendLine("It looks like you may be missing binding redirects in your config file, try to add the following binding redirects:");

                const string bindingRedirects = @"<runtime>
    <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
        <dependentAssembly>
        <assemblyIdentity name=""NServiceBus.Core"" publicKeyToken=""9fc386479f8a226c"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-{0}"" newVersion=""{0}"" />
        </dependentAssembly>
        <dependentAssembly>
        <assemblyIdentity name=""NServiceBus"" publicKeyToken=""9fc386479f8a226c"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-{0}"" newVersion=""{0}"" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>";

                sb.AppendFormat(bindingRedirects, nsbAssemblyName.Version.ToString(4));
                sb.AppendLine();

            }

            return sb.ToString();
        }
Example #17
0
 public LoadingAssemblyTypesEventArgs(Assembly assemblyFile, System.Reflection.ReflectionTypeLoadException exception)
 {
     AssemblyFile = assemblyFile;
     Exception = exception;
 }
        private static bool InterceptReflectionTypeLoadException(ReflectionTypeLoadException outerException, out IEnumerable<string> complaints)
        {
            var badFiles = new Dictionary<string, string>();
            foreach (var exception in outerException.LoaderExceptions)
            {
                var fileNotFound = exception as FileNotFoundException;
                var fileLoadError = exception as FileLoadException;
                string fileName = null;
                if (fileNotFound != null)
                {
                    fileName = fileNotFound.FileName;
                }
                else if (fileLoadError != null)
                {
                    fileName = fileLoadError.FileName;
                }

                if (fileName != null)
                {
                    if (badFiles.ContainsKey(fileName)) 
                    {
                        // Don't overright first entry for this file, because it probably contains best error
                    }
                    else
                    {
                        badFiles.Add(fileName, exception.Message);
                    }
                }
                else
                {
                    // we haven't anticipated this specific exception, so rethrow.
                    complaints = null;
                    return false;
                }
            }            
            // experience shows that dependency errors in ReflectionTypeLoadExceptions tend to be redundant.
            // here, we ensure that each missing dependency is reported only once.
            complaints = 
                badFiles.Select(
                    (fileName, msg) =>
                        String.Format("An assembly dependency {0} could not be loaded: {1}", fileName, msg)).ToArray();
            // exception was anticipated.
            return true;
        }
Example #19
0
        public UnableToGetTypesException(ReflectionTypeLoadException rtle)
            : base(rtle.Message)
        {
            loaderMessages = new string[rtle.LoaderExceptions.Length];

            for (int i = 0; i < rtle.LoaderExceptions.Length; i++)
            {
                loaderMessages[i] = rtle.LoaderExceptions[i].Message;
            }
        }
		public void VerifyNetReflectorTypeLoadExceptionMessage()
		{
			ReflectionTypeLoadException innerException = new ReflectionTypeLoadException(new Type[] {typeof (TestClass), null}, new Exception[] {new TypeLoadException("Failed to load TestSubClass")});
			Assembly assembly = Assembly.GetCallingAssembly();
			NetReflectorTypeLoadException exception = new NetReflectorTypeLoadException(assembly, innerException);
			AssertContains(assembly.GetName().ToString(), exception.Message);
			AssertContains("Failed to load 1 of the 2 types defined in the assembly.", exception.Message);
			AssertContains("Failed to load TestSubClass", exception.Message);
		}
Example #21
0
        internal static string FormatReflectionTypeLoadException(string fileName, ReflectionTypeLoadException e)
        {
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("Could not enumerate all types for '{0}'. Exception message: {1}.", fileName, e));

            if (!e.LoaderExceptions.Any())
            {
                return sb.ToString();
            }

            sb.AppendLine("Scanned type errors:");
            foreach (var ex in e.LoaderExceptions)
            {
                sb.AppendLine(ex.ToString());
            }

            return sb.ToString();
        }
Example #22
0
 private static void DumpReflectionTypeLoadException(ReflectionTypeLoadException loadException, StringBuilder sb)
 {
     if (loadException != null)
     {
         sb.AppendLine("LoaderExceptions property value:");
         foreach (var loaderException in loadException.LoaderExceptions)
         {
             sb.AppendFormat("[{0} : {1}]", loaderException.GetType().FullName, loaderException.Message).AppendLine();
         }
         sb.AppendLine("End of Loader Exceptions");
     }
 }
Example #23
0
File: Demo.cs Project: wli3/Its.Log
        public void Formatting3_Exception_formatting_is_very_descriptive_by_default()
        {
            Log.EntryPosted += (sender, e) => Console.WriteLine(e.LogEntry.ToLogString());

            var dataException = new DataException("oops!");
            dataException.Data["why?"] = "because";
            var outerException = new ReflectionTypeLoadException(new[] { GetType() }, new[] { dataException });

            try
            {
                throw outerException;
            }
            catch (Exception ex)
            {
                Log.Write(() => ex);
            }
        }
 private void DisplayLoaderExceptionsOnConsole(ReflectionTypeLoadException e)
 {
     foreach (var loaderException in e.LoaderExceptions)
     {
         Console.WriteLine(loaderException.ToString());
     }
 }
Example #25
0
        internal static string FormatReflectionTypeLoadException(string fileName, ReflectionTypeLoadException e)
        {
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("Could not enumerate all types for '{0}'.", fileName));

            if (!e.LoaderExceptions.Any())
            {
                sb.AppendLine(string.Format("Exception message: {0}", e));
                return sb.ToString();
            }

            var nsbAssemblyName = typeof(AssemblyScanner).Assembly.GetName();
            var nsbPublicKeyToken = BitConverter.ToString(nsbAssemblyName.GetPublicKeyToken()).Replace("-", "").ToLowerInvariant();
            var displayBindingRedirects = false;
            var files = new List<string>();
            var sbFileLoadException = new StringBuilder();
            var sbGenericException = new StringBuilder();

            foreach (var ex in e.LoaderExceptions)
            {
                var loadException = ex as FileLoadException;

                if (loadException != null)
                {
                    var assemblyName = new AssemblyName(loadException.FileName);
                    var assemblyPublicKeyToken = BitConverter.ToString(assemblyName.GetPublicKeyToken()).Replace("-", "").ToLowerInvariant();
                    if (nsbAssemblyName.Name == assemblyName.Name &&
                        nsbAssemblyName.CultureInfo.ToString() == assemblyName.CultureInfo.ToString() &&
                        nsbPublicKeyToken == assemblyPublicKeyToken)
                    {
                        displayBindingRedirects = true;
                        continue;
                    }

                    if (!files.Contains(loadException.FileName))
                    {
                        files.Add(loadException.FileName);
                        sbFileLoadException.AppendLine(loadException.FileName);
                    }
                    continue;
                }

                sbGenericException.AppendLine(ex.ToString());
            }

            if (sbGenericException.ToString().Length > 0)
            {
                sb.AppendLine("Exceptions:");
                sb.AppendLine(sbGenericException.ToString());
            }

            if (sbFileLoadException.ToString().Length > 0)
            {
                sb.AppendLine("It looks like you may be missing binding redirects in your config file for the following assemblies:");
                sb.Append(sbFileLoadException);
                sb.AppendLine("For more information see http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.100).aspx");
            }

            if (displayBindingRedirects)
            {
                sb.AppendLine();
                sb.AppendLine("Try to add the following binding redirects to your config file:");

                const string bindingRedirects = @"<runtime>
    <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
        <dependentAssembly>
        <assemblyIdentity name=""NServiceBus.Core"" publicKeyToken=""9fc386479f8a226c"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-{0}"" newVersion=""{0}"" />
        </dependentAssembly>
        <dependentAssembly>
        <assemblyIdentity name=""NServiceBus"" publicKeyToken=""9fc386479f8a226c"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-{0}"" newVersion=""{0}"" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>";

                sb.AppendFormat(bindingRedirects, nsbAssemblyName.Version.ToString(4));
                sb.AppendLine();
            }

            return sb.ToString();
        }
Example #26
0
        public void StripReflectionTypeLoadException()
        {
            _client.AddWrapperExceptions(typeof(ReflectionTypeLoadException));

              FileNotFoundException ex1 = new FileNotFoundException();
              FileNotFoundException ex2 = new FileNotFoundException();
              ReflectionTypeLoadException wrapper = new ReflectionTypeLoadException(new Type[] { typeof(FakeRaygunClient), typeof(WrapperException) }, new Exception[] { ex1, ex2 });

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(2, exceptions.Count);
              Assert.Contains(ex1, exceptions);
              Assert.Contains(ex2, exceptions);

              Assert.IsTrue(ex1.Data["Type"].ToString().Contains("FakeRaygunClient"));
              Assert.IsTrue(ex2.Data["Type"].ToString().Contains("WrapperException"));
        }
Example #27
0
 private static void PrintReflectionTypeLoadException(ReflectionTypeLoadException e)
 {
     LogWriteLine("---- LoaderExceptions:");
     var count = 1;
     foreach (var ex in e.LoaderExceptions)
     {
         LogWriteLine("---- LoaderException #" + count++);
         LogWrite(ex.GetType().Name);
         LogWrite(": ");
         LogWriteLine(ex.Message);
         LogWriteLine(ex.StackTrace);
     }
     LogWriteLine("---- LoaderException Types:");
     foreach (var type in e.Types)
     {
         LogWriteLine(type);
     }
 }
Example #28
0
 public LoadPluginException(Assembly assembly, ReflectionTypeLoadException exception)
     : base(niceMessage(assembly, exception), exception)
 {
 }
Example #29
0
        private static string GetReflectionTypeLoadExceptionMessage(ReflectionTypeLoadException exception)
        {
            StringBuilder builder = new StringBuilder();
            // lookup table for duplicate messages
            List<string> messages = new List<string>(); 

            builder.AppendLine(exception.Message);
            builder.AppendLine(Properties.Resources.LoaderExceptionMessages);
            foreach (Exception error in exception.LoaderExceptions)
            {
                if (!messages.Contains(error.Message))
                {
                    builder.AppendLine(error.Message);
                    messages.Add(error.Message);
                }
            }

            builder.AppendLine(Properties.Resources.LoaderExceptionTypeMessages);
            foreach (Type type in exception.Types)
            {
                if (type != null && 
                    !messages.Contains(type.FullName))
                {
                    builder.AppendLine(type.FullName);
                    messages.Add(type.FullName);
                }
            }

            return builder.ToString();
        }
        public DefaultHttpControllerTypeResolverTracerTest()
        {
            ExpectedTypes = new List<Type>
            {
                typeof(ValidController), typeof(UsersRpcController), typeof(UsersController),
            };

            Type[] fine1Types = new Type[]
            {
                typeof(DefaultHttpControllerTypeResolverTracerTest),
                null,
                typeof(ValidController),
            };
            Type[] poorTypes = new Type[]
            {
                typeof(string),
                null,
                typeof(Action),
                null,
                typeof(UsersRpcController),
            };
            Type[] fine2Types = new Type[]
            {
                typeof(DefaultHttpControllerTypeResolver),
                null,
                typeof(DefaultHttpControllerTypeResolverTracer),
                null,
                typeof(UsersController)
            };

            Exception worseException = new Exception(ExceptionMessage);
            Exception poorException = new ReflectionTypeLoadException(poorTypes, new Exception[] { worseException });
            ExpectedTraces = new List<TraceRecord>
            {
                new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Debug)
                {
                    Kind = TraceKind.Begin,
                    Operator = "DefaultHttpControllerTypeResolverProxy", // Moq type name
                    Operation = "GetControllerTypes",
                },
                new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Warn)
                {
                    Kind = TraceKind.Trace,
                    Exception = poorException,
                    Message = "Exception thrown while getting types from 'PoorAssembly'.",
                },
                new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Warn)
                {
                    Kind = TraceKind.Trace,
                    Exception = worseException,
                    Message = "Exception thrown while getting types from 'WorseAssembly'.",
                },
                new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Debug)
                {
                    Kind = TraceKind.End,
                    Operator = "DefaultHttpControllerTypeResolverProxy",
                    Operation = "GetControllerTypes",
                },
            };

            Mock<MockableAssembly> fine1Assembly = new Mock<MockableAssembly>(MockBehavior.Strict);
            fine1Assembly.Setup(assembly => assembly.GetTypes()).Returns(fine1Types);
            fine1Assembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);

            Exception[] exceptions = new Exception[] { new Exception(ExceptionMessage), };
            Mock<MockableAssembly> poorAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
            poorAssembly.Setup(assembly => assembly.GetTypes()).Throws(poorException);
            poorAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
            poorAssembly.SetupGet(assembly => assembly.FullName).Returns("PoorAssembly");

            Mock<MockableAssembly> worseAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
            worseAssembly.Setup(assembly => assembly.GetTypes()).Throws(worseException);
            worseAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
            worseAssembly.SetupGet(assembly => assembly.FullName).Returns("WorseAssembly");

            Mock<MockableAssembly> fine2Assembly = new Mock<MockableAssembly>(MockBehavior.Strict);
            fine2Assembly.Setup(assembly => assembly.GetTypes()).Returns(fine2Types);
            fine2Assembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);

            Mock<MockableAssembly> dynamicAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
            dynamicAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(true);

            Assemblies = new Mock<MockableAssembly>[]
            {
                fine1Assembly,
                poorAssembly,
                worseAssembly,
                fine2Assembly,
                dynamicAssembly,
            };

            AssembliesResolver = new Mock<IAssembliesResolver>(MockBehavior.Strict);
            AssembliesResolver.Setup(resolver => resolver.GetAssemblies()).Returns(
                Assemblies.Select(assembly => (Assembly)assembly.Object).AsCollection());

            HttpControllerTypeResolver =
                new Mock<DefaultHttpControllerTypeResolver>() { CallBase = true, };
        }
Example #31
0
 protected override void HandlePluginLoadReflectionException(PluginData data, ReflectionTypeLoadException ex)
 {
     base.HandlePluginLoadReflectionException(data, ex);
     active_plugin = null;
 }
Example #32
0
        public void Exceptions_always_get_properties_formatters()
        {
            var exception = new ReflectionTypeLoadException(
                new[]
                {
                    typeof (FileStyleUriParser),
                    typeof (AssemblyKeyFileAttribute)
                },
                new Exception[]
                {
                    new EventLogInvalidDataException()
                });
            var formatter = new FormatterSet();

            var message = formatter.Format(exception);

            Assert.That(message,
                        Contains.Substring("ReflectionTypeLoadException"));
            Assert.That(message,
                        Contains.Substring("FileStyleUriParser"));
            Assert.That(message,
                        Contains.Substring("AssemblyKeyFileAttribute"));
            Assert.That(message,
                        Contains.Substring("EventLogInvalidDataException"));
        }