The executable does not work with a strange exception

I am using ILMerge and Quartz.NET in a Windows Service C # .NET 4.0 application. The application works fine without using ILMerge, but now that we are approaching the delivery release, I wanted to combine all the DLLs into one executable file.

The problem is that ILMerge is working fine, but when I run the combined executable, it throws this exception:

Unhandled exception: Quartz.SchedulerException: ThreadPool type 'Quartz.Simpl.SimpleThreadPool' could not be created. ---> System.InvalidCastException: it is not possible to drop an object of type Quartz.Simpl.SimpleThreadPool to enter "Quartz.Spi.IThreadPool".
in Quartz.Util.ObjectUtils.InstantiateType [T] (Type): line 0
in Quartz.Impl.StdSchedulerFactory.Instantiate () in: line 0
--- End of internal check for exception stack ---
in Quartz.Impl.StdSchedulerFactory. Instantiate () in: line 0
in Quartz.Impl.StdSchedulerFactory.GetScheduler () in: line 0

Does anyone know why this is? I have been spending more than 4 hours, and I can’t understand. If I do not combine with ILMerge, everything works fine (with Quartz.dll and Common.Logging.dll in the same directory).

I am sure someone must have tried Quartz.net packaging, as it was before, any ideas?

+5
source share
2 answers

Disclaimer . I don't know Quartz.NET at all, although I struggled with ILMerge for a while. When I finally understood its limitations ... I stopped using it.

The ILMerge'd app has problems with everything that contains the word reflection. I can guess (I never used Quartz.NET) that some classes are solved using reflection and are managed by configuration files.

( ), ( , ). , , ( ILMerging) A ( Application) Q ( Quartz.NET). "A" "Q" Q: QClass, "Q: QIntf". "A: QClass" "A: QIntf" ( Q A), () /, "A: QClass" "A: QIntf" . / , - "Q: QClass".

, , - "Q: QClass" ( , , "Q" , , GAC - . 1). "Q: QClass" "A: QIntf" , - "Q: QIntf", , "Q: QClass" "A: QIntf" .

, "" "" . , ( ), . , , .

  • , (, ) Q.dll . , "FileNotFound".
+1

ISchedulerFactory . StdSchedulerFactory . , :

        Type tpType = loadHelper.LoadType(cfg.GetStringProperty(PropertyThreadPoolType)) ?? typeof(SimpleThreadPool);

        try
        {
            tp = ObjectUtils.InstantiateType<IThreadPool>(tpType);
        }
        catch (Exception e)
        {
            initException = new SchedulerException("ThreadPool type '{0}' could not be instantiated.".FormatInvariant(tpType), e);
            throw initException;
        }

ObjectUtils.InstantiateType, , , - :

    public static T InstantiateType<T>(Type type)
    {
        if (type == null)
        {
            throw new ArgumentNullException("type", "Cannot instantiate null");
        }
        ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
        if (ci == null)
        {
            throw new ArgumentException("Cannot instantiate type which has no empty constructor", type.Name);
        }
        return (T) ci.Invoke(new object[0]);
    }

factory , , , JobFactory. Quartz.Net , .

+1

All Articles