Coder Social home page Coder Social logo

Comments (6)

sflusov avatar sflusov commented on July 19, 2024

Hi @HakanL ,

We've occurred with the same problem in integration tests and solved it via adding pdftools to DI container.

Please have a look in our code

public void ConfigureServices(IServiceCollection services)
{
    // let's register pdf tools for correct ending the chrome process
    // when application shutting down
    services.AddSingleton(typeof(ITools), typeof(PdfTools);
	
    // this scenario apply only in multi-thread scenario like in a webserver
    // see also: https://github.com/rdvojmoc/DinkToPdf#dependency-injection
    services.AddSingleton(typeof(IConverter), typeof(SynchronizedConverter);
}

If it looks normal I will prepare pull request to the documentation

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

@sflusov Yeah, that's a workaround (to always hold a reference to it), but the issue is if you want to do a teardown then it's not working.

from wkhtmltopdf-dotnet.

sflusov avatar sflusov commented on July 19, 2024

We have ~1.5k integration tests which use WebApplicationFactory (TestServer) and there is no problem run it again and again.
Maybe you lost dispose method in the end of test collection.

So If you provide example of code I will try to help you

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

It's not a problem if you don't try to dispose (which is typically the setup with DI), but this bug was raised because it didn't work to tear it down. We would probably need to add a separate unit test to the project to test repeated setup/teardown, I don't think there is one currently, PRs welcome.

from wkhtmltopdf-dotnet.

TomGullen avatar TomGullen commented on July 19, 2024

Doing:

using(var converter = new SynchronizedConverter(new PdfTools())){
    ... do
}

Works the first time, but crashes the application on subsequent calls to this method.

This is solved by keeping one copy of SynchronizedConverter as a static variable, but rebuilding the site fails with the error:

The process cannot access the file '\bin\runtimes\win-x64\native\wkhtmltox.dll' because it is being used by another process. The file is locked by: "w3wp.exe (16856)"

Docs need to be clearer on how to use SynchronizedConverter and it looks like a bit of a showstopper bug for us that something isn't being disposed properly.

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

@TomGullen You should always just have a singleton/static instance of the SynchronizedConverter when using this project. I assume the teardown issue has something to do with the native library, but more investigation is needed. The examples in here use the SynchronizedConverter, but feel free to submit PR for how the docs can be improved.

from wkhtmltopdf-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.