# Object Initializer: "The object constructor ... has no argument or settable return property..."

**URL:** <https://forums.fsharp.org/t/object-initializer-the-object-constructor-has-no-argument-or-settable-return-property/3930>\
**Category:** General\
**Tags:** beginners\
**Created:** [November 25, 2024, 8:57pm UTC](https://forums.fsharp.org/t/object-initializer-the-object-constructor-has-no-argument-or-settable-return-property/3930 "2024-11-25T20:57:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spearruleina](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@Spearruleina](https://forums.fsharp.org/u/Spearruleina)\
**Post date:** [November 25, 2024, 8:57pm UTC](https://forums.fsharp.org/t/object-initializer-the-object-constructor-has-no-argument-or-settable-return-property/3930/1 "2024-11-25T20:57:35Z")

</div>

Hi,  
I have looked around the Googular response  
(only really seen one: [f# - Object initialization syntax - Stack Overflow](https://stackoverflow.com/questions/371878/object-initialization-syntax) ; )  
and hit my head against a wall on this a couple of different times, but now it bugs me enough that i seek assistance (perhaps that i may hit my head smarter, not harder?).

C# lets you do this with Object Initializer syntax.

```csharp
// Deserialize using altername names.
var inputOptions = new JsonSerializerOptions
{
    TypeInfoResolver = new DefaultJsonTypeInfoResolver
    {
        Modifiers = { JsonExtensions.UseAternameNames<Json3rdPartyAlternativeNameAttribute>() },
    },
};

```

Writing the F# equivalent following the above stackoverflow link has worked for me in the past with certain Properties, passing them as named arguments in F# (so long as they allow **set** ting!)  
But the documentation for [Modifiers](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.metadata.defaultjsontypeinforesolver.modifiers?view=net-9.0#system-text-json-serialization-metadata-defaultjsontypeinforesolver-modifiers) property calls it a ‘get’ only. Not even ‘init’.

So how does C# even let you do this?  
Further (and more importantly for my case : ),  
how can i set this Property in F# (when i try, i get the above error from the subject).

Thank you,  
-Gerald

---

<div class="post-metadata">

**Author:** ![diana45peters](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@diana45peters](https://forums.fsharp.org/u/diana45peters)\
**Post date:** [December 12, 2024, 2:26pm UTC](https://forums.fsharp.org/t/object-initializer-the-object-constructor-has-no-argument-or-settable-return-property/3930/3 "2024-12-12T14:26:56Z")

</div>

Hi Gerald,

I understand your frustration! Let’s break it down:

In C#, the `Object Initializer` syntax allows you to set properties during object creation without explicitly invoking a constructor. This is possible because the compiler processes the object initializer by first accessing the parameterless constructor and then processing the member initializations1.

However, in F#, the equivalent is done using **object expressions**. Unfortunately, if a property is marked as `get` only (read-only), you can’t set it directly.

```auto
type JsonSerializerOptions() =
    member val TypeInfoResolver = new DefaultJsonTypeInfoResolver() with get

let inputOptions = 
    { JsonSerializerOptions.TypeInfoResolver with
        Modifiers = [JsonExtensions.UseAternameNames<Json3rdPartyAlternativeNameAttribute>()]
    }

```

In this example, we’re using an object expression to create an instance of `JsonSerializerOptions` and then modifying the `TypeInfoResolver` property [wellnow near me](https://www.wellnow-urgentcare.com)
