Hi
We are using your printer library in a service. This service has a plugin framework and each plugin is executed in its own AppDomain.
We now experience that the plugins may no longer be unloaded after using the Printer class and this is a big issue on our side. The following code is sufficient to mess the AppDomain up:
Printer printer = new Printer("Microsoft XPS Document Writer");
So I tried to find some workarounds but there is none. I made a small demo application which demonstrates the issue. Just create a new console application, add a referance to your printing library and paste the following code in the main class:
using System;
using System.Linq;
using System.Reflection;
namespace CeTePrinterAddIn
{
public class Program
{
[STAThread]
public static void Main(string[] args)
{
string path = @"C:\Lib\ceTe.DynamicPDF.Printing.40.x64.dll";
try
{
string pathToDll = Assembly.GetExecutingAssembly().CodeBase;
AppDomainSetup domainSetup = new AppDomainSetup { PrivateBinPath = pathToDll };
AppDomain domain = AppDomain.CreateDomain("TempDomain", null, domainSetup);
InstanceProxy proxy = domain.CreateInstanceFromAndUnwrap(pathToDll, typeof(InstanceProxy).FullName) as InstanceProxy;
if (proxy != null)
{
proxy.LoadPrinter(path);
}
AppDomain.Unload(domain);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
}
internal class InstanceProxy : MarshalByRefObject
{
public void LoadPrinter(string path)
{
Assembly asm = Assembly.LoadFrom(path);
Type[] types = asm.GetExportedTypes();
Type type = types.FirstOrDefault(t => (t.FullName == "ceTe.DynamicPDF.Printing.Printer"));
ConstructorInfo constructor = type.GetConstructors().FirstOrDefault();
object printer = constructor.Invoke(new[] { "Microsoft XPS Document Writer" });
Console.WriteLine(printer.ToString());
}
}
}
Please fix this issue and let me know of new version. I think Printer should inherit from IDisposable or similar to clean up non-native stuff as well.
AppDomain fails to unload when CeTePrinter is used
Re: AppDomain fails to unload when CeTePrinter is used
Forum member · Oct 17, 2014I messed my post up a little. Don't add a reference to your library, but adjust the path in the code on the first line.
Re: AppDomain fails to unload when CeTePrinter is used
Support · Oct 22, 2014Hello,
We are currently investigating this issue. We will post and update as soon as we have some new information to share.
Thanks,
ceTe Software Support Team.
Re: AppDomain fails to unload when CeTePrinter is used
Forum member · Nov 4, 2014May I ask you if there is some progress on this issue?
Re: AppDomain fails to unload when CeTePrinter is used
Support · Nov 6, 2014Hello,
A fix is available for this issue now. Please email us at [^a|mailto:support@cete.com|opennewwindow|support@cete.com^] to obtain the fix.
Thanks,
ceTe Software Support Team.