I cannot figure out a relative path that works for my resource. I’ve tried everything I could think of. The only thing that works is an absolute path that is only correct on my system, but would be incorrect in any deployed version.
As far as I know, this very simple path should work.
public class GreyscaleEffect : ShaderEffect
{
private static PixelShader _pixelShader = new PixelShader()
{ UriSource = new Uri("/Effects/Greyscale.ps", UriKind.Relative) };
For which I get the error The type initializer for 'FSR.WPF.Utilities.UI. GreyscaleEffect' threw an exception. Inner Exception: Cannot locate resource 'effects/greyscale.ps'.
I’ve also tried the following:
Uri(";component/Effects/Greyscale.ps", UriKind.Relative)
Uri("/;component/Effects/Greyscale.ps", UriKind.Relative)
Uri("/FSR.WPF.Utilities.UI;component/Effects/Greyscale.ps", UriKind.Relative)
Elsewhere (in a xaml file in MUSUI), the following path is used, and it works fine:
<Image Source="/FSR.WPF.Utilities.UI;component/assets/CurrencyFlags/USD.png"
So I can’t figure out why this case, which is so similar, doesn’t work.
Only the following absolute path works:
Uri("C:\TFS\MUS 6.1.x\Mosaic Middleware\FSR.WPF.Utilities\FSR.WPF.Utilities.UI" +
"\Effects\Greyscale.ps")
I’ve also tried all of the above with every combination of using @ in front of the string, using UriKind.Absolute, and leaving out the second parameter altogether. Nothing works but the absolute path and I’m losing my mind.
Here’s the solution structure. The Main project is MUSUI, at the bottom in bold. This effect class and .ps file are both in the Effects folder which is at the root of a referenced assembly FSR.WPF.Utilities.UI.

Anyways, I know this has to work somehow. Anyone that can figure out the shortest working relative path possible, especially if it doesn’t require hard-coding in the assembly name, gets the prize.
You can’t specify a relative URI, it must be absolute. When you specify a relative URI in XAML, it is actually converted into an absolute URI using
IUriContext.BaseUri, but in C# code there is no information about the current location, so you can’t use a relative URI.You need to specify the URI by using the
pack://URI scheme: