XamlParseException in app.xaml resource strings

I have the following code in App.xaml:

<Application x:Class="PcgTools.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:local="clr-namespace:PcgTools.ViewModels" 
         xmlns:res="clr-namespace:PcgTools.Resources"
         StartupUri="MainWindow.xaml"
         Startup="Application_Startup">
    <Application.Resources>
        <ResourceDictionary>
            ...
            <res:Strings x:Key="LocStrings"/>
        </ResourceDictionary> 
    </Application.Resources>
</Application>

(...... some lines that I deleted to make the example cleaner).

When I launch the application, I get the following error (immediately after trying to start / debug): (translation from Dutch, so it may not be 100% literally equal):

No matching constructor was found in type PcgTools.Resources.Strings. You can use the Arguments or FactoryMethod statement to create this type.

There is a constructor file Strings.Designer.cs in the file:

namespace PcgTools.Resources {
...
public class Strings {
...

[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute
   ("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Strings() {
    }

However, it is generated, so I can’t even change it.

Btw, it worked without changing the code (about a week ago), but in about 30% of cases when debugging gave this error, and after a second attempt, this exception did not occur.

+2
2

PcgTools.Resources.Strings ? , , , , Arguments, ( ). , .

, - . FactoryMethods . ,

namespace PcgTools.Resources
{
    public static class StringResourceHelper
    {
        public static strings GetStringResources()
        {
            return new Resources.Strings();
        }
    }
}

XAML :

<res:Strings x:FactoryMethod="res:StringResourceHelper.GetStringResources" 
             x:Key="LocStrings"/>
+2

. :

http://dotnet.dzone.com/news/did-you-know-silverlight-class

: .Resources "", , .

: (..Designer.cs) - , , .

0

Source: https://habr.com/ru/post/1783274/


All Articles