Share via

How to avoid load system DLL while creating application using WPF

Prashant Sharma 0 Reputation points
2025-10-23T10:26:01.02+00:00

I have application in WPF C#, When I run process mon I can see list of System DLL

  • cryptsp.dll
  • CRYPTBASE.dll
  • bcrypt.dll
  • MSVCP140_CLR0400.dll
  • profapi.dll
  • USP10.dll
  • msls31.dll
  • NTASN1.dll By placing a malicious DLL with the same name in the application directory, arbitrary code execution was achieved. How to avoid such case.
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


2 answers

Sort by: Most helpful
  1. Susmitha T (INFOSYS LIMITED) 2,695 Reputation points Microsoft External Staff
    2025-10-28T11:16:16.8566667+00:00

    Thanks for reaching out!

    To prevent, you can restrict your WPF application from loading malicious system DLLs by calling
    SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32) early in the app startup (e.g., in App.xaml.cs). This ensures only the trustable system locations like System32 are used for DLL loading.

    Additionally, install the app in protected folders (e.g., program files), avoid loading DLLs by name without full paths, and sign your binaries for integrity.

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    Was this answer helpful?


  2. Bruce (SqlWork.com) 84,086 Reputation points
    2025-10-24T23:18:50.2266667+00:00

    You get around this by only using signed dlls. Most system dlls are signed. If you are creating your own, then you must sign them:

    https://learn.microsoft.com/en-us/dotnet/standard/assembly/sign-strong-name

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.