예제 #1
0
        internal static TypeLoadException TypeLoad(string error)
        {
            TypeLoadException e = new TypeLoadException(error);

            TraceExceptionAsReturnValue(e);
            return(e);
        }
예제 #2
0
            private static T GetInstance()
            {
                var theType = typeof(T);
                T   inst;

                try
                {
                    inst = (T)theType
                           .InvokeMember(theType.Name,
                                         BindingFlags.CreateInstance | BindingFlags.Instance
                                         | BindingFlags.NonPublic,
                                         null, null, null,
                                         CultureInfo.InvariantCulture);
                }
                catch (MissingMethodException ex)
                {
                    var exception = new TypeLoadException(string.Format(
                                                              CultureInfo.CurrentCulture,
                                                              "The type '{0}' must have a private constructor to " +
                                                              "be used in the Singleton pattern.", theType.FullName)
                                                          , ex);
                    //LogManager.LogException(LogManager.EventIdInternal, exception, "error in instantiating the singleton");
                    throw exception;
                }
                return(inst);
            }
    public bool PosTest1()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 1, 255);
        TypeLoadException tLE = new TypeLoadException(errMessage);

        String expectedValue = errMessage;
        String actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Get Message when the message is a random string");
        try
        {
            actualValue = tLE.Message;

            if (!actualValue.Equals(expectedValue))
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
    public bool PosTest2()
    {
        bool retVal = true;

        String errMessage = null;
        TypeLoadException tLE = new TypeLoadException(errMessage);

        String expectedValue = "Failure has occurred while loading a type.";
        //when message is null,it will return the default message.

        String actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest2:Get Message when the message is a null string");
        try
        {
            actualValue = tLE.Message;

            if ((actualValue != expectedValue) &
                !(actualValue.Contains("[Arg_TypeLoadException]")))
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
예제 #5
0
        public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement()
        {
            using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
            {
                XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:r='http://www.springframework.net/remoting'>  
    
    <r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' />
    
    <object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' />

    <object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
        <property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter, Spring.Services.Tests' />
        <property name='target' ref='ISimpleCounter'/>
    </object>
</objects>
"));
                try
                {
                    SaoExporter saoExporter = (SaoExporter)of.GetObject("ISimpleCounterExporter");
                    Assert.Fail();
                }
                catch (ObjectCreationException oce)
                {
                    TypeLoadException tle = (TypeLoadException)oce.GetBaseException();
                    Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message);
                }
            }
        }
예제 #6
0
        public static void Ctor_Empty()
        {
            var exception = new TypeLoadException();

            ExceptionHelpers.ValidateExceptionProperties(exception, hResult: COR_E_TYPELOAD, validateMessage: false);
            Assert.Equal("", exception.TypeName);
        }
        public object GetValue(ITypeResolutionService typeResolver)
        {
            if (this.value != null)
            {
                return(this.value);
            }
            object obj2 = null;

            if (this.FileRefFullPath != null)
            {
                if (this.ResolveType(this.FileRefType, typeResolver) != null)
                {
                    if (this.FileRefTextEncoding != null)
                    {
                        this.fileRef = new ResXFileRef(this.FileRefFullPath, this.FileRefType, Encoding.GetEncoding(this.FileRefTextEncoding));
                    }
                    else
                    {
                        this.fileRef = new ResXFileRef(this.FileRefFullPath, this.FileRefType);
                    }
                    return(TypeDescriptor.GetConverter(typeof(ResXFileRef)).ConvertFrom(this.fileRef.ToString()));
                }
                TypeLoadException exception = new TypeLoadException(System.Windows.Forms.SR.GetString("TypeLoadExceptionShort", new object[] { this.FileRefType }));
                throw exception;
            }
            if ((obj2 == null) && (this.nodeInfo.ValueData != null))
            {
                return(this.GenerateObjectFromDataNodeInfo(this.nodeInfo, typeResolver));
            }
            return(null);
        }
        public static void Ctor_String()
        {
            string message   = "type failed to load";
            var    exception = new TypeLoadException(message);

            ExceptionHelpers.ValidateExceptionProperties(exception, hResult: COR_E_TYPELOAD, message: message);
            Assert.Equal("", exception.TypeName);
        }
        public static void Ctor_String_Exception()
        {
            string message        = "type failed to load";
            var    innerException = new Exception("Inner exception");
            var    exception      = new TypeLoadException(message, innerException);

            ExceptionUtility.ValidateExceptionProperties(exception, hResult: COR_E_TYPELOAD, innerException: innerException, message: message);
            Assert.Equal("", exception.TypeName);
        }
        /// <summary>
        /// Helper routine for the more general Module.GetType() family of apis. Also used in typeRef resolution.
        ///
        /// Resolves top-level named types only. No nested types. No constructed types. The input name must not be escaped.
        ///
        /// If a type is not contained or forwarded from the assembly, this method returns null (does not throw.)
        /// This supports the "throwOnError: false" behavior of Module.GetType(string, bool).
        /// </summary>
        protected sealed override RoDefinitionType GetTypeCoreNoCache(ReadOnlySpan <byte> ns, ReadOnlySpan <byte> name, out Exception e)
        {
            MetadataReader reader = Reader;

            // Look through types declared in the manifest module.
            foreach (TypeDefinitionHandle h in reader.TypeDefinitions)
            {
                TypeDefinition td = h.GetTypeDefinition(reader);
                if (td.IsNested)
                {
                    continue;  // GetTypeCore() is never asked to look for nested types.
                }
                if (!(td.Name.Equals(name, reader)))
                {
                    continue;
                }
                if (!(td.Namespace.Equals(ns, reader)))
                {
                    continue;
                }

                e = null;
                return(h.ResolveTypeDef(this));
            }

            // Look for forwarded types.
            foreach (ExportedTypeHandle h in reader.ExportedTypes)
            {
                ExportedType et = h.GetExportedType(reader);
                if (!et.IsForwarder)
                {
                    continue;
                }

                EntityHandle implementation = et.Implementation;
                if (implementation.Kind != HandleKind.AssemblyReference) // This check also weeds out nested types. This is intentional.
                {
                    continue;
                }

                if (!(et.Name.Equals(name, reader)))
                {
                    continue;
                }

                if (!(et.Namespace.Equals(ns, reader)))
                {
                    continue;
                }

                RoAssembly assembly = ((AssemblyReferenceHandle)implementation).TryResolveAssembly(this, out e);
                return(assembly?.GetTypeCore(ns, name, ignoreCase: false, out e));
            }

            e = new TypeLoadException(SR.Format(SR.TypeNotFound, ns.ToUtf16().AppendTypeName(name.ToUtf16()), FullyQualifiedName));
            return(null);
        }
예제 #11
0
        internal void HandleTypeLoadException(TypeLoadException ex)
        {
            if (ex == null)
            {
                return;
            }

            string message = ex.Message;

            if (!existedExceptions.ContainsKey(this))
            {
                existedExceptions[this] = new Collection <string>();
            }

            if (!existedExceptions[this].Contains(message))
            {
                existedExceptions[this].Add(message);

                //string tempMessage1 = string.Format(CultureInfo.InvariantCulture, "A TypeLoadException is caught. This exception might cause by a breaking change of MapSuite APIs. It will break functionality of {0}. Please ", ex.Source);
                //string tempMessage2 = string.Format(CultureInfo.InvariantCulture, " to update corresponding assemblies. ");

                GisEditorMessageBox messageBox = new GisEditorMessageBox(MessageBoxButton.OK);
                messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                messageBox.Owner   = Application.Current.MainWindow;
                messageBox.Title   = "Info";
                messageBox.Message = string.Format(CultureInfo.InvariantCulture, "A TypeLoadException is caught. This exception might because \"{0}\" plugin's version is not match this GIS Editor or some plugin(s) don’t implement the required APIs. Please update the plugins to match this version of GIS Editor. Remove those plugins would also remove this exception.", ex.Source);

                //Run run = new Run("contact ThinkGeo");
                //Hyperlink hyperlink = new Hyperlink(run);
                //hyperlink.Click += (s, e) =>
                //{
                //    messageBox.Close();
                //    GisEditor.LoggerManager.Log(LoggerLevel.Error, message, ex);
                //};
                //messageBox.Inlines.Add(tempMessage1);
                //messageBox.Inlines.Add(hyperlink);
                //messageBox.Inlines.Add(tempMessage2);

                StringBuilder sb = new StringBuilder();
                sb.Append(String.Format(CultureInfo.InvariantCulture, "Source: \t{0}\r\n", ex.Source));
                sb.Append(String.Format(CultureInfo.InvariantCulture, "Message: \t{0}\r\n", ex.Message));
                sb.Append(String.Format(CultureInfo.InvariantCulture, "Stack: \t{0}\r\n", ex.StackTrace));
                messageBox.ErrorMessage = sb.ToString();

                messageBox.ToggleButtonClickAction = new Action(() =>
                {
                    messageBox.Close();
                    GisEditor.LoggerManager.Log(LoggerLevel.Error, message, ex);
                });

                messageBox.ShowDialog();
            }

            GisEditor.LoggerManager.Log(LoggerLevel.Debug, message, ex);
        }
        public void CanBeCreatedWithMessageAndExceptionTest()
        {
            var exceptionMessage      = Guid.NewGuid().ToString();
            var innerExceptionMessage = Guid.NewGuid().ToString();

            var innerException = new TypeLoadException(innerExceptionMessage);
            var target         = new HtmlElementNotFoundException(exceptionMessage, innerException);

            target.Message.Should().Be(exceptionMessage);
            target.InnerException.Should().Be(innerException);
        }
예제 #13
0
        private static WrapperEngineLoadException WrapTypeLoadException(
            TypeLoadException originalTypeLoadException)
        {
            string originalMessage = originalTypeLoadException.Message;
            string description;
            string message;

            Match errorMessageMatch = _interfaceAssemblyLoadErrorMessage.Match(originalMessage);

            if (errorMessageMatch.Success)
            {
                string assemblyFileName = errorMessageMatch.Groups["assemblyFileName"].Value;

                var           stringBuilderPool  = StringBuilderPool.Shared;
                StringBuilder descriptionBuilder = stringBuilderPool.Rent();
                descriptionBuilder.AppendFormat(CoreStrings.Engine_AssemblyNotFound, assemblyFileName);
                descriptionBuilder.Append(" ");
                if (assemblyFileName == DllName.V8LibCpp64Bit || assemblyFileName == DllName.V8LibCpp32Bit)
                {
                    descriptionBuilder.AppendFormat(CoreStrings.Engine_NuGetPackageInstallationRequired,
                                                    assemblyFileName == DllName.V8LibCpp64Bit ?
                                                    "JavaScriptEngineSwitcher.V8.Native.win-x64"
                                                        :
                                                    "JavaScriptEngineSwitcher.V8.Native.win-x86"
                                                    );
                    descriptionBuilder.Append(" ");
                    descriptionBuilder.Append(Strings.Engine_VcRedist2017InstallationRequired);
                }
                else
                {
                    descriptionBuilder.AppendFormat(CoreStrings.Common_SeeOriginalErrorMessage, originalMessage);
                }

                description = descriptionBuilder.ToString();
                stringBuilderPool.Return(descriptionBuilder);

                message = JsErrorHelpers.GenerateEngineLoadErrorMessage(description, EngineName);
            }
            else
            {
                description = originalMessage;
                message     = JsErrorHelpers.GenerateEngineLoadErrorMessage(description, EngineName, true);
            }

            var wrapperEngineLoadException = new WrapperEngineLoadException(message, EngineName, EngineVersion,
                                                                            originalTypeLoadException)
            {
                Description = description
            };

            return(wrapperEngineLoadException);
        }
예제 #14
0
 /// <exception cref="System.TypeLoadException"/>
 protected override Type LoadClass(string name, bool resolve)
 {
     lock (this)
     {
         if (Log.IsDebugEnabled())
         {
             Log.Debug("Loading class: " + name);
         }
         Type c = FindLoadedClass(name);
         TypeLoadException ex = null;
         if (c == null && !IsSystemClass(name, systemClasses))
         {
             // Try to load class from this classloader's URLs. Note that this is like
             // the servlet spec, not the usual Java 2 behaviour where we ask the
             // parent to attempt to load first.
             try
             {
                 c = FindClass(name);
                 if (Log.IsDebugEnabled() && c != null)
                 {
                     Log.Debug("Loaded class: " + name + " ");
                 }
             }
             catch (TypeLoadException e)
             {
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug(e);
                 }
                 ex = e;
             }
         }
         if (c == null)
         {
             // try parent
             c = parent.LoadClass(name);
             if (Log.IsDebugEnabled() && c != null)
             {
                 Log.Debug("Loaded class from parent: " + name + " ");
             }
         }
         if (c == null)
         {
             throw ex != null ? ex : new TypeLoadException(name);
         }
         if (resolve)
         {
             ResolveClass(c);
         }
         return(c);
     }
 }
예제 #15
0
        /// <summary>
        ///    Get the value contained in this datanode
        /// </summary>
        public object GetValue(ITypeResolutionService typeResolver)
        {
            if (value != null)
            {
                return(value);
            }

            object result = null;

            if (FileRefFullPath != null)
            {
                Type objectType = ResolveType(FileRefType, typeResolver);
                if (objectType != null)
                {
                    // we have the FQN for this type
                    if (FileRefTextEncoding != null)
                    {
                        fileRef = new ResXFileRef(FileRefFullPath, objectType.AssemblyQualifiedName,
                                                  Encoding.GetEncoding(FileRefTextEncoding));
                    }
                    else
                    {
                        fileRef = new ResXFileRef(FileRefFullPath, objectType.AssemblyQualifiedName);
                    }

                    TypeConverter tc = TypeDescriptor.GetConverter(typeof(ResXFileRef));
                    result = tc.ConvertFrom(fileRef.ToString());
                }
                else
                {
                    string            newMessage = string.Format(SR.TypeLoadExceptionShort, FileRefType);
                    TypeLoadException newTle     = new TypeLoadException(newMessage);
                    throw (newTle);
                }
            }
            else if (nodeInfo.ValueData != null)
            {
                // it's embedded, we deserialize it
                result = GenerateObjectFromDataNodeInfo(nodeInfo, typeResolver);
            }
            else
            {
                // schema is wrong and say minOccur for Value is 0,
                // but it's too late to change it...
                // we need to return null here
                return(null);
            }

            return(result);
        }
        public void GetTypeFactory_ArgsMissingWhenCalling_ThrowsArgumentNullException()
        {
            FactoryDelegate factory = DynamicMethodGenerator.GetTypeFactory(
                typeof(Example),
                typeof(string), typeof(string), typeof(string), typeof(int), typeof(int), typeof(int), typeof(string), typeof(string), typeof(string));

            Assert.NotNull(factory);

            TypeLoadException ex = Assert.Throws <TypeLoadException>(
                delegate()
            {
                var actual = (Example)factory("alpha", "bravo", "charlie", -1, -2, -3);
            });
        }
예제 #17
0
        private static WrapperEngineLoadException WrapTypeLoadException(
            TypeLoadException originalTypeLoadException)
        {
            string originalMessage = originalTypeLoadException.Message;
            string description;
            string message;

            Match errorMessageMatch = _libraryLoadErrorMessage.Match(originalMessage);

            if (errorMessageMatch.Success)
            {
                string assemblyFileName = errorMessageMatch.Groups["assemblyFileName"].Value;

                var           stringBuilderPool  = StringBuilderPool.Shared;
                StringBuilder descriptionBuilder = stringBuilderPool.Rent();
                descriptionBuilder.AppendFormat(CoreStrings.Engine_AssemblyNotFound, assemblyFileName);
                descriptionBuilder.Append(" ");

                string packageName;
                if (_nativeAssemblyPackageMap.TryGetValue(assemblyFileName, out packageName))
                {
                    descriptionBuilder.AppendFormat(CoreStrings.Engine_NuGetPackageInstallationRequired, packageName);
                }
                else
                {
                    descriptionBuilder.AppendFormat(CoreStrings.Common_SeeOriginalErrorMessage, originalMessage);
                }

                description = descriptionBuilder.ToString();
                stringBuilderPool.Return(descriptionBuilder);

                message = JsErrorHelpers.GenerateEngineLoadErrorMessage(description, EngineName);
            }
            else
            {
                description = originalMessage;
                message     = JsErrorHelpers.GenerateEngineLoadErrorMessage(description, EngineName, true);
            }

            var wrapperEngineLoadException = new WrapperEngineLoadException(message, EngineName, EngineVersion,
                                                                            originalTypeLoadException)
            {
                Description = description
            };

            return(wrapperEngineLoadException);
        }
        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());
        }
예제 #19
0
        /// <summary>
        /// Returns an object instantiated by the Activator, using fully-qualified asm/type supplied.
        /// Permits construction arguments to be supplied which it passes to the object's constructor on instantiation.
        /// </summary>
        /// <param name="assemblyName">fully-qualified assembly name</param>
        /// <param name="typeName">the type name</param>
        /// <param name="constructorArguments">constructor arguments for type to be created</param>
        /// <returns>instance of requested assembly/type typed as System.Object</returns>
        public static object Create(string assemblyName, string typeName, object[] constructorArguments)
        {
            Assembly assemblyInstance = null;
            Type     typeInstance     = null;

            try
            {
                //  use full asm name to get assembly instance
                assemblyInstance = Assembly.Load(assemblyName.Trim());
            }
            catch (Exception e)
            {
                string error = ApplicationUpdateManager.TraceWrite("[GenericFactory.Create]", "RES_EXCEPTION_CantLoadAssembly", assemblyName, typeName);

                TypeLoadException tle = new TypeLoadException(error, e);
                ExceptionManager.Publish(tle);
                throw tle;
            }

            try
            {
                //  use type name to get type from asm; note we WANT case specificity
                typeInstance = assemblyInstance.GetType(typeName.Trim(), true, false);

                //  now attempt to actually create an instance, passing constructor args if available
                if (constructorArguments != null)
                {
                    return(Activator.CreateInstance(typeInstance, constructorArguments));
                }
                else
                {
                    return(Activator.CreateInstance(typeInstance));
                }
            }
            catch (Exception e)
            {
                string error = ApplicationUpdateManager.TraceWrite("[GenericFactory.Create]", "RES_EXCEPTION_CantCreateInstanceUsingActivate", assemblyName, typeName);

                TypeLoadException tle = new TypeLoadException(error, e);
                ExceptionManager.Publish(tle);
                throw tle;
            }
        }
예제 #20
0
        public void Construct_Given_Type_And_TypeLoaderException_ShouldSetProperties()
        {
            //---------------Set up test pack-------------------
            var type           = GetType();
            var innerException = new TypeLoadException($"Access denied: {RandomValueGen.GetRandomString()}");

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var sut = new UnableToCreateDynamicBuilderException(type, innerException);

            //---------------Test Result -----------------------
            var typeName = type.PrettyName();

            Expect(sut.Message)
            .To.Start.With($"Unable to create dynamic builder for type {typeName}. If {typeName} is internal, you should make InternalsVisibleTo \"PeanutButter.RandomGenerators.GeneratedBuilders\"");
            Expect(sut.Type).To.Equal(type);
            Expect(sut.InnerException).To.Equal(innerException);
        }
예제 #21
0
    /// <summary>
    /// Informs RhinoCommon of an exception that has been handled but that the developer wants to screen.
    /// </summary>
    /// <param name="source">An exception source text.</param>
    /// <param name="ex">An exception.</param>
    public static void ExceptionReport(string source, Exception ex)
    {
      if (null == ex)
        return;
      string msg = ex.ToString();

      TypeLoadException tle = ex as TypeLoadException;
      if (tle != null)
      {
        string name = tle.TypeName;
        //if (!string.IsNullOrEmpty(name))
        msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}\nMissing Type = {1}", msg, name);
      }
      if (!string.IsNullOrEmpty(source))
        DebugString(source);
      DebugString(msg);

      if (OnExceptionReport != null)
        OnExceptionReport(source, ex);
    }
예제 #22
0
        private void LoadType(Type type)
        {
            var typeLoadEx = new TypeLoadException(
                string.Format("Unable to GetType() for {0}. Check if the Type name is correct", type));

            var typeInitEx = new TypeInitializationException(
                string.Format("Unable to load {0}. Check if the Type name is correct", type),
                typeLoadEx);

            if (type == null)
            {
                throw typeLoadEx;
            }

            Scanner = (IBarcodeScanner)Activator.CreateInstance(type);
            if (Scanner == null)
            {
                throw typeInitEx;
            }
        }
        public void CanBeSerializedAndDeserializedTest()
        {
            var exceptionMessage      = Guid.NewGuid().ToString();
            var innerExceptionMessage = Guid.NewGuid().ToString();
            var innerException        = new TypeLoadException(innerExceptionMessage);
            var target = new HtmlElementNotFoundException(exceptionMessage, innerException);

            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();

                formatter.Serialize(ms, target);
                ms.Seek(0, SeekOrigin.Begin);

                var outputException = formatter.Deserialize(ms) as HtmlElementNotFoundException;

                outputException.Should().NotBeNull();
                target.Message.Should().Be(exceptionMessage);
                target.InnerException.Should().Be(innerException);
            }
        }
예제 #24
0
    public bool PosTest2()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 1, 255);

        TestLibrary.TestFramework.BeginScenario("PosTest2:Determine the error message is changed or not when the exception is thown out");
        try
        {

            TypeLoadException tLE = new TypeLoadException(errMessage);

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("004", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
예제 #25
0
        public Type ResolveAnnotation(string className)
        {
            Type clazz = null;
            TypeLoadException firstException = null;

            foreach (var classNameCandidate in GetAnnotationNames(className))
            {
                try {
                    clazz = ResolveClassInternal(classNameCandidate, true, true, ExtensionClassEmpty.INSTANCE);
                }
                catch (TypeLoadException e) {
                    firstException ??= e;
                }
            }

            if (clazz == null)
            {
                throw new ImportException("Could not load annotation class by name '" + className + "', please check imports", firstException);
            }

            return(clazz);
        }
예제 #26
0
        /// <summary>
        /// Uses a file path to load an assembly.  Then instantiates the requested type by searching interfaces.
        /// Returns an object instantiated by the Activator, using fully-qualified combined assembly-type  supplied.
        /// Assembly parameter example: "Microsoft.ApplicationBlocks.ApplicationUpdater,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"
        /// Type parameter example: "Microsoft.ApplicationBlocks.ApplicationUpdater.Validators.RSAValidator"
        /// </summary>
        /// <param name="filePath">full path to assembly</param>
        /// <param name="interfaceToActivate">the Type representing the interface to activate</param>
        /// <returns></returns>
        public static object Create(string filePath, Type interfaceToActivate)
        {
            Assembly asm          = null;
            Type     typeInstance = null;

            Type[] types = null;
            Object obj   = null;

            try
            {
                asm   = Assembly.LoadFrom(filePath);
                types = asm.GetTypes();
                //  walk through all types in assembly, find the one that IS IPP and use its info
                foreach (Type type in types)
                {
                    //  search for interface by string name in this type
                    typeInstance = type.GetInterface(interfaceToActivate.FullName, false);
                    //  if we find the interface, return the type that implements it
                    if (null != typeInstance)
                    {
                        //  we found the first instance of the given interface
                        //  THERE MAY BE MORE but this is a convenience method.
                        typeInstance = type;
                        break;
                    }
                }
                obj = asm.CreateInstance(typeInstance.FullName);
            }
            catch (Exception e)
            {
                string error = ApplicationUpdateManager.TraceWrite("[GenericFactory.Create]", "RES_EXCEPTION_CantCreateInstanceFromFilePath", filePath, interfaceToActivate);

                TypeLoadException tle = new TypeLoadException(error, e);
                ExceptionManager.Publish(tle);
                throw tle;
            }

            return(obj);
        }
예제 #27
0
    public bool PosTest3()
    {
        bool retVal = true;

        String errMessage = String.Empty;

        TestLibrary.TestFramework.BeginScenario("PosTest3:Determine the method with Empty String");
        try
        {
            TypeLoadException tLE = new TypeLoadException(errMessage, new Exception());

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("006", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("007", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #28
0
    public bool PosTest2()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 1, 255);

        TestLibrary.TestFramework.BeginScenario("PosTest2:Determine the error message is changed or not when the exception is thown out");
        try
        {
            TypeLoadException tLE = new TypeLoadException(errMessage, new Exception());

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("004", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #29
0
    public bool PosTest4()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 256, 512);

        TestLibrary.TestFramework.BeginScenario("PosTest4:Determine the method with Long String");
        try
        {
            TypeLoadException tLE = new TypeLoadException(errMessage, new Exception());

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("009", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("010", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("011", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #30
0
        public void BadV8Deployment_NoNativeLibrary()
        {
            V8Proxy.RunWithDeploymentDir("BadV8Deployment_NoNativeLibrary", () =>
            {
                var testException = new Win32Exception(126 /*ERROR_MOD_NOT_FOUND*/);
                TypeLoadException caughtException = null;

                try
                {
                    using (new V8ScriptEngine())
                    {
                    }
                }
                catch (TypeLoadException exception)
                {
                    caughtException = exception;
                }

                Assert.IsNotNull(caughtException);
                // ReSharper disable once PossibleNullReferenceException
                Assert.IsTrue(caughtException.Message.Contains(testException.Message));
            });
        }
예제 #31
0
        private static string GetLocalizedEffectErrorMessage(Assembly assembly, Type type, Exception exception)
        {
            IPluginSupportInfo pluginSupportInfo;
            string             fullName;

            if (type != null)
            {
                fullName          = type.FullName;
                pluginSupportInfo = PluginSupportInfo.GetPluginSupportInfo(type);
            }
            else if (exception is TypeLoadException)
            {
                TypeLoadException exception2 = exception as TypeLoadException;
                fullName          = exception2.TypeName;
                pluginSupportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
            }
            else
            {
                pluginSupportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
                fullName          = null;
            }
            return(GetLocalizedEffectErrorMessage(assembly, fullName, pluginSupportInfo, exception));
        }
예제 #32
0
    public bool PosTest1()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 1, 255);

        TestLibrary.TestFramework.BeginScenario("PosTest1:Create a instance of TypeLoadException");
        try
        {
            TypeLoadException tLE = new TypeLoadException(errMessage, new Exception());

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
예제 #33
0
    public bool PosTest1()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 1, 255);

        TestLibrary.TestFramework.BeginScenario("PosTest1:Create a instance of TypeLoadException");
        try
        {
            TypeLoadException tLE = new TypeLoadException(errMessage);

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
예제 #34
0
        public void Exceptions_GetTypeLoadTypes()
        {
            TypeLoadException typeLoadEx = null;

            try
            {
                // cause a type load exception to have it filled with a type name
                Assembly.GetExecutingAssembly().GetType("NonExistentType.TypeLoadException", true);
            }
            catch (TypeLoadException ex)
            {
                typeLoadEx = ex;
            }

            var rTle = new ReflectionTypeLoadException(new Type[0], new Exception[]
            {
                new FileLoadException("error", "FileLoadException.dll"),
                new FileNotFoundException("error", "FileNotFoundException.dll"),
                new BadImageFormatException("error", "BadImageFormatException.dll"),
                new SecurityException("error")
                {
                    Url = "SecurityException.dll"
                },
                typeLoadEx
            });

            var types = Utility.GetTypeLoadErrorTypes(rTle);

            Assert.AreEqual(string.Join(",",
                                        "FileLoadException.dll",
                                        "FileNotFoundException.dll",
                                        "BadImageFormatException.dll",
                                        "SecurityException.dll",
                                        "NonExistentType.TypeLoadException"),
                            string.Join(",", types));
        }
예제 #35
0
    public bool PosTest4()
    {
        bool retVal = true;

        String errMessage = TestLibrary.Generator.GetString(-55, false, 256, 512);

        TestLibrary.TestFramework.BeginScenario("PosTest4:Determine the method with Long String");
        try
        {

            TypeLoadException tLE = new TypeLoadException(errMessage);

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("009", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("010", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("011", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
예제 #36
0
    public bool PosTest3()
    {
        bool retVal = true;

        String errMessage = String.Empty;

        TestLibrary.TestFramework.BeginScenario("PosTest3:Determine the method with Empty String");
        try
        {

            TypeLoadException tLE = new TypeLoadException(errMessage);

            if (tLE == null)
            {
                TestLibrary.TestFramework.LogError("006", "ExpectedValue(not null) !=ActualValue(null)");
                retVal = false;
            }
            else
            {
                retVal = false;
                throw tLE;
            }
        }
        catch (TypeLoadException eE)
        {
            retVal = true;
            if (!eE.Message.Equals(errMessage))
            {
                TestLibrary.TestFramework.LogError("007", "ExpectedValue(Message Not Be Changed) !=ActualValue(Message Be Changed)");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
    public bool PosTest3()
    {
        bool retVal = true;

        String errMessage = "";
        TypeLoadException tLE = new TypeLoadException(errMessage);

        String expectedValue = errMessage;
        String actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest3:Get Message when the message is a empty string");
        try
        {
            actualValue = tLE.Message;

            if (!actualValue.Equals(expectedValue))
            {
                TestLibrary.TestFramework.LogError("005", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }