LechExt
LechExt

Reputation: 27

Why have to add to GAC. DLL already given in exe folder

I wrote an shell extension in c#. App shows WPF Dialogs and I use Xaml.Behaviors When I run the App. All other DLL are found. (Same Folder as exe) But App throw an exception for missing Microsoft.Xaml.Behaviors.dll (but is actually there in same folder)

so I run: gacutil.exe /i ...\bin\Debug\Microsoft.Xaml.Behaviors.dll This fix my issue.

My quesion is why other dlls are found and not xmal_behaviors?

Is it possible to skip the GAC step?

Update:

Upvotes: 1

Views: 120

Answers (2)

Andy
Andy

Reputation: 12276

Behaviors is now offered as a nuget package.

The way you're intended to use them is to Manage Nuget Packages, find Microsoft.Xaml.Behaviors.Wpf and "install" that.

eg

enter image description here

You then need a xmlns in your view.

         xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

And an example usage:

                <TextBox Text="{Binding NettPer, StringFormat='{}{0:C}'}" Grid.Column="1">
                    <i:Interaction.Behaviors>
                        <b:SelectAllTextBoxBehavior/>
                    </i:Interaction.Behaviors>

The above is from a real solution, which is compiled to target .net 6 and works fine without that behaviors dll in the machine GAC.

If this doesn't work then it's probably due to an incompatibility. AFAIK Microsoft's advice is still not to write shell extensions in managed code. I can't find a current link but the below was as of 2018. https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/dd758089(v=vs.85)

Upvotes: 0

MD Zand
MD Zand

Reputation: 2605

Try adding a reference to the DLL in your project and set the "Copy Local" property to true. This will cause the DLL to be copied to the output directory of your application when it is built, and loaded from that location at runtime.

Upvotes: 1

Related Questions