4

The URI prefix is not recognized

I am getting the above error message in a System.NotSupportedException.

This line is used to set the source of a ResourceDictionary:

view.Source = new Uri("/DA.EasyTeach.Math;component/View.xaml", UriKind.RelativeOrAbsolute);

This is a snip of my file structure:
enter image description here

View.xaml has a Build Action of Resource.

afaolek
  • 8,452
  • 13
  • 45
  • 60
  • Try `new Uri("pack://application:,,,/DA.EasyTeach.Math;component/View.xaml")` without UriKind. See [Resource File Pack URIs](https://msdn.microsoft.com/en-us/library/aa970069(v=vs.100).aspx#Resource_File_Pack_URIs___Local_Assembly). Also make sure that `DA.EasyTeach.Math` is an assembly name, not a namespace. – Clemens Apr 14 '16 at 10:38
  • Still getting the same error – afaolek Apr 14 '16 at 10:52
  • @Clemens It's a `ResourceDictionary`, not `Frame`. `View.xaml` contains a `DataTemplate`. – afaolek Apr 14 '16 at 11:12

3 Answers3

6

I have a hybrid application WinForms + WPF and the cause was System.Windows.Application.Current == null. Based on this question I solved it by running following line before creating dictionary Uri:

new System.Windows.Application();
Community
  • 1
  • 1
Jan Zahradník
  • 2,417
  • 2
  • 33
  • 44
0

I finally discovered that the issue was not about the Uri. The ResourceDictionary was part of a plugin for a MEF application. I only had to merge the ResourceDictionary with the resources in the host. Solved!

I'm only putting this as an answer since it could help someone else.

afaolek
  • 8,452
  • 13
  • 45
  • 60
0

Probably it could happen when you use multi-windowed application.

So in such case the possible solution can be to set Application shutdown mode:

public AppConstuctor()
{
    ShutdownMode = ShutdownMode.OnExplicitShutdown;
}

or in xaml:

<Application ...
             ShutdownMode="OnExplicitShutdown">
...
</Application>