---
title: "RVN001 - Index Map or Reduce assigned outside constructor"
description: "RVN001* reports assignments to an index's Map or Reduce property inside a method instead of directly in the constructor."
url: "https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN001"
version: "7.2"
---

# RVN001 - Index Map or Reduce assigned outside constructor

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - **RVN001** reports assignments to an index's `Map` or `Reduce` property inside a method instead of directly in the constructor.
>
> - **Default severity**: *Info*  
>   **Automated code fix**: *No*
>
> - In this article:
>   - [Description](#description)
>   - [Trigger condition](#trigger-condition)
>     - [When is RVN001 reported?](#when-is-rvn001-reported)
>     - [When is RVN001 not reported?](#when-is-rvn001-not-reported)
>   - [How to resolve](#how-to-resolve)
>     - [Before (triggers RVN001)](#before-triggers-rvn001)
>     - [After (correct)](#after-correct)
>   - [Limitations](#limitations)
>   - [Related C# analyzers](#related-c-analyzers)

## Description {#description}

The RavenDB client builds the index definition from the `Map` and `Reduce` expressions when the index is deployed.  
If these expressions are assigned in a separate method, that method may not run before the definition is built,  
for example if it is called conditionally or not at all.

For single-map document indexes, the client throws `InvalidOperationException` if `Map` is still unset when the definition is built.
If `Reduce` is unset, the resulting definition is map-only.

## Trigger condition {#trigger-condition}

RVN001 checks index classes derived from the following bases:

- `AbstractIndexCreationTask<TDocument>`, `AbstractIndexCreationTask<TDocument, TReduceResult>`,
  or `AbstractGenericIndexCreationTask<TReduceResult>`.
- `AbstractMultiMapIndexCreationTask`, `AbstractMultiMapTimeSeriesIndexCreationTask`,
  or `AbstractMultiMapCountersIndexCreationTask`, including their generic variants.

Abstract index classes are checked too.  
Multi-map indexes have no `Map` property, so only `Reduce` assignments apply to them.

RVN001 also reports `Reduce` assignments in JavaScript indexes derived from `AbstractJavaScriptIndexCreationTask`.
Assignments to their `Maps` property are not checked.

### When is RVN001 reported?

RVN001 is reported when `Map` or `Reduce` is assigned inside an ordinary method of a supported index class,
including assignments inside lambdas or local functions nested in that method.
Both block-bodied and expression-bodied methods are checked.

The assignment must use an unqualified property name (`Map` or `Reduce`),
`this.Map` / `this.Reduce`, or `base.Map` / `base.Reduce`.

RVN001 does not trace calls. It is still reported when the method is always called from a constructor,
or when it reassigns a property the constructor already set.

### When is RVN001 not reported?

RVN001 is not reported for:

- Assignments in constructors, including lambdas or local functions nested in them.
- Assignments in property or indexer accessors, operators, or finalizers.
- Assignments to local variables or parameters named `Map` or `Reduce`.
- Assignments through another object, such as `other.Map` or `other.Reduce`.
- Calls to `AddMap` or `AddMapForAll` inside methods.
- Single-map time-series and counters indexes based on `AbstractTimeSeriesIndexCreationTask<...>`
  or `AbstractCountersIndexCreationTask<...>`.

## How to resolve {#how-to-resolve}

Move the reported `Map` or `Reduce` assignment directly into the constructor body.

---

### Before (triggers RVN001)

```csharp
public class Orders_ByCompany : AbstractIndexCreationTask<Order>
{
    public void Configure()
    {
        // Triggers RVN001 even though the constructor always calls Configure().
        Map = orders => from o in orders
                        select new { o.Company, o.Employee };
    }

    public Orders_ByCompany()
    {
        Configure();
    }
}
```

### After (correct)

```csharp
public class Orders_ByCompany : AbstractIndexCreationTask<Order>
{
    public Orders_ByCompany()
    {
        Map = orders => from o in orders
                        select new { o.Company, o.Employee };
    }
}
```

## Limitations {#limitations}

- A partial class declaration that lists neither a base class nor any interfaces is skipped.
  Assignments in methods declared in that part are not checked, even when another part declares the index base class.

- RVN001 can also report assignments to custom fields or properties named `Map` or `Reduce` on an index class,  
  even when they are unrelated to the index definition.

## Related C# analyzers {#related-c-analyzers}

- [RVN004](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN004.md)  
  Fires when no constructor sets `Map`, directly or through a method it calls.  
  RVN001 and RVN004 can both be reported when `Map` is assigned only in a method that no constructor calls.

- [RVN005](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN005.md)  
  Fires when no constructor registers a map through `AddMap` or `AddMapForAll`, directly or through a method it calls.

## See also

- [C# code analyzers overview](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/overview.md)
- [Creating and deploying indexes](https://docs.ravendb.net/7.2/indexes/creating-and-deploying.md)
- [Map indexes](https://docs.ravendb.net/7.2/indexes/map-indexes.md)
- [Map-reduce indexes](https://docs.ravendb.net/7.2/indexes/map-reduce-indexes.md)
