Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF designer error Value cannot be null. Parameter name: pattern

I've seen a lot of other ObjectDataProvider questions where the Parameter name: type, name, whatever, cannot be null. Those questions are all due to actual parameters not being set. As far as I can tell, there is no "pattern" parameter for an ObjectDataProvider. The following markup produces "Value cannot be null. Parameter name: pattern", with the accompanying blue squiggle underline. Occasionally the designer throws an exception and fails to load, however pressing the reload button loads the page. The code and markup compile and run as expected. What is causing this?

<Page.Resources>
...
    <ObjectDataProvider ObjectType="{x:Type local:AutoFillBox}" MethodName="RecUpdateOutput" x:Key="odpOutput">
        <ObjectDataProvider.MethodParameters>
            <sys:String>08:00</sys:String>
            <sys:String>12:00</sys:String>
            <sys:String>13:00</sys:String>
            <sys:String>18:00</sys:String>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Page.Resources>

Part of the class, wanted to note this is not a custom control, just a poor naming choice:

    public partial class AutoFillBox
    {
        public AutoFillBox()
        { //default }

        public string RecUpdateOutput(string time1, string time2, string time3, string time4)
        {
            //do stuff
        }
    }

It's the only ObjectDataProvider on the page, and if I remove the 4th string parameter the error goes away. Additionally, the method it calls does take 4 strings, and returns a string so I can bind it's result to an output textbox. I use a similar ObjectDataProvider on a different page with a similar method and signature, and it also shows the same error. What the heck is going on here?

Visual Studio Ultimate 2013, Windows 7 Professional, targeting .net 4.5

like image 575
user2943131 Avatar asked Sep 30 '22 13:09

user2943131


1 Answers

I don't believe it's a VS bug. Try adding the property IsAsynchronous="True" to the ObjectDataProvider and that should eliminate the designer error. The property defaults to False and the designer will try to create the object in the active context. Here's link:

ObjectDataProvider

Worked for me. Hope it works for you.

like image 101
user3786916 Avatar answered Oct 04 '22 19:10

user3786916