{"id":1136,"date":"2018-08-20T17:05:35","date_gmt":"2018-08-20T16:05:35","guid":{"rendered":"http:\/\/piatkosia.k4be.pl\/wordpress\/?p=1136"},"modified":"2019-04-20T14:31:13","modified_gmt":"2019-04-20T13:31:13","slug":"typeinitializationexception-2","status":"publish","type":"post","link":"https:\/\/piatkosia.k4be.pl\/wordpress\/en\/2018\/08\/20\/typeinitializationexception-2\/","title":{"rendered":"TypeInitializationException"},"content":{"rendered":"<p>There is some kind of errors, which you can easily fix by edit (or move) only one line of code. My last error is one of them. I don&#8217;t remember when I made it, because I can&#8217;t recall a birthday of my last line written by hand). Ok, not completely by hand, because I used snippet &#8222;propdp&#8221;, which are used to generate properties, which we can use from XAML level for example. This snippet before edition looks like this (after double tab):<br \/>\n<!--more--><\/p>\n<pre class=\"brush: csharp; collapse: false\">public int MyProperty\n\t\t{\n\t\t\tget { return (int)GetValue(MyPropertyProperty); }\n\t\t\tset { SetValue(MyPropertyProperty, value); }\n\t\t}\n\n\t\t\/\/ Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...\n\t\tpublic static readonly DependencyProperty MyPropertyProperty =\n\t\t\tDependencyProperty.Register(\"MyProperty\", typeof(int), typeof(ownerclass), new PropertyMetadata(0));\n<\/pre>\n<p>I want bool, not int, so I fix one by one and I have sth like this after that:<\/p>\n<pre class=\"brush: csharp; collapse: false\">public bool LoadIt\n\t\t{\n\t\t\tget { return (bool)GetValueLoadItProperty); }\n\t\t\tset { SetValue(LoadItProperty, value); }\n\t\t}\n\n\t\t\/\/Ten komentarz oczywi\u015bcie wyrzuci\u0142am bo mi po co\n\t\tpublic static readonly DependencyProperty LoadItProperty =\n\t\t\tDependencyProperty.Register(\"LoadIt\", typeof(bool), typeof(MyWindowClass), new PropertyMetadata(0));\n<\/pre>\n<p>It looks like this.<\/p>\n<p>I press the green triangle, and I&#8217;m sure it must work. I don&#8217;t do it first time, and &#8230; ouch, something is broken.<\/p>\n<p style=\"text-align: justify;\">I have TypeInitializationException from title. My first reaction&#8230; no, it must be censored, because children can read it, but when I mastered the world flow composed of the words underlined in red by word application and mastered the wave of self-aggression, I decided that before I use the &#8222;search error in stack overflow&#8221; function in my VS, I read what says &#8222;exception message&#8221;.<\/p>\n<p style=\"text-align: justify;\">In general, it has a problem with cast &#8222;0&#8221; :p Ok, I forgot to change default value. Stupid distracted blonde girl- PropertyMetadata must take false as default value:)<\/p>\n<p>So the last line must look like this:<\/p>\n<pre class=\"brush: csharp; collapse: false\">\t\tpublic static readonly DependencyProperty CzyMaBycZaladowaneProperty =\n\t\t\tDependencyProperty.Register(\"CzyMaBycZaladowane\", typeof(bool), typeof(MojeOkienko), new PropertyMetadata(false));\n<\/pre>\n<p>And that&#8217;s all<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is some kind of errors, which you can easily fix by edit (or move) only one line of code. My last error is one<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/piatkosia.k4be.pl\/wordpress\/en\/2018\/08\/20\/typeinitializationexception-2\/\">Lecim dalej<span class=\"screen-reader-text\">TypeInitializationException<\/span> <i class=\"fas fa-angle-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[583,645,581],"tags":[590,595,619],"class_list":["post-1136","post","type-post","status-publish","format-standard","hentry","category-c_sharp-en","category-gmtl","category-programming","tag-c_sharp-en","tag-dependency-property-en","tag-gmtl","entry"],"_links":{"self":[{"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/posts\/1136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/comments?post=1136"}],"version-history":[{"count":2,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/posts\/1136\/revisions"}],"predecessor-version":[{"id":1139,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/posts\/1136\/revisions\/1139"}],"wp:attachment":[{"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/media?parent=1136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/categories?post=1136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/piatkosia.k4be.pl\/wordpress\/wp-json\/wp\/v2\/tags?post=1136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}