HwndSource constructor fails with "The RPC server is unavailable"

Günther Humer 1 Reputation point
2022-10-31T13:35:29.637+00:00

Recently the code creating a HwndSource is throwing an Exception in KernelBase.dll.
Visual Studio 2022 with all Exceptions turned on.

It has happend only recently, is 100% reproducable and does happen on Windows 10 and not on Windows 11.

Also tried other sample code from https://daniel-albuschat.blogspot.com/2011/05/using-net-and-wpf-in-win32-legacy.html which has the same problem.

System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters ();  
 sourceParams->PositionX = x;  
 sourceParams->PositionY = y;  
 sourceParams->Height = height;  
 sourceParams->Width = width;  
 sourceParams->ParentWindow = System::IntPtr(this->parent_);  
 this->hwndSource_ = gcnew System::Windows::Interop::HwndSource(*sourceParams);  

Is this sth to worry about?

255702-image.png

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,697 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,600 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hui Liu-MSFT 46,961 Reputation points Microsoft Vendor
    2022-11-01T03:15:07.993+00:00

    Hi,@Günther Humer . Welcome Microsoft Q&A.
    This has nothing to do with your project.Nothing actually went wrong, the exception was caught and handled. Explorer implements counter-measures against bad shell extensions destabilizing it and automatically disables them. So you just have a lame-duck shell extension that doesn't work.
    The debugger can tell you which one is bad. Enable unmanaged debugging and tick the Thrown checkboxes in the Debug + Exception dialog. The debugger will now stop when the exception is thrown. You won't see any source code but you can look at the Call Stack debugger window for hints. It displays the name of the DLL that contain the bad code somewhere on the stack, below the Windows DLL functions. The name ought to give you a hint which one is the troublemaker. SysInternals' AutoRuns utility is excellent to disable them.
    You could also see if solution a and solution b helped you.

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Günther Humer 1 Reputation point
    2022-11-08T11:40:54.57+00:00

    It suddenly stopped from appearing.

    Anyway I don't understand, what HWNDSOURCE and Wpf Interop has to do with Explorer?

    0 comments No comments