---
title: "RVN004 - AbstractIndexCreationTask subclass is missing a Map assignment"
description: "RVN004* reports a missing Map assignment in a RavenDB index class."
url: "https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN004"
version: "7.2"
---

# RVN004 - AbstractIndexCreationTask subclass is missing a Map assignment

> 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**
>
> - **RVN004** reports a missing `Map` assignment in a RavenDB index class.
>
> - **Default severity**: *Info*  
>   **Automated code fix**: *No*
>
> - In this article:
>   - [Description](#description)
>   - [Trigger condition](#trigger-condition)
>     - [When is RVN004 reported?](#when-is-rvn004-reported)
>     - [When is RVN004 not reported?](#when-is-rvn004-not-reported)
>   - [How to resolve](#how-to-resolve)
>     - [Before (triggers RVN004)](#before-triggers-rvn004)
>     - [After (correct)](#after-correct)
>   - [Limitations](#limitations)
>   - [Related C# analyzers](#related-c-analyzers)

## Description {#description}

Indexes that derive from `AbstractIndexCreationTask<TDocument>` or `AbstractIndexCreationTask<TDocument, TReduceResult>`
and use the standard `CreateIndexDefinition()` implementation must assign `Map` before the client builds the index definition.

Without a `Map`, the client throws `InvalidOperationException` ("*Map is required to generate an index…*") when it builds the index definition,
so the index is never deployed.

When indexes are deployed together through `IndexCreation.CreateIndexes()` or `store.ExecuteIndexes()`,  
a missing `Map` prevents every index in that batch from being deployed.

## Trigger condition {#trigger-condition}

### When is RVN004 reported?

RVN004 is reported when no `Map` assignment is reachable from any constructor of the index class or its base classes,
including a base class from a referenced project.

RVN004 is still reported when `Map` is assigned only in a method that no constructor calls,  
even if that method runs before the client builds the index definition.

### When is RVN004 not reported?

An assignment found in any constructor of the index class or its base classes is enough to suppress RVN004.
Assignments in methods of those classes also count when a constructor calls the method, directly or through other methods.

RVN004 recognizes assignments written as `Map = ...`, `this.Map = ...`, or `base.Map = ...`.  
See [Limitations](#limitations) for cases where an assignment counts even though it may not execute.

RVN004 is also not reported for the following index classes, even when no `Map` assignment is found:

- Abstract index classes. Their subclasses are checked instead.
- Indexes that override `CreateIndexDefinition()`.
- Multi-map indexes. See [RVN005](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN005.md).
- JavaScript indexes (`AbstractJavaScriptIndexCreationTask`), which define their maps as strings.
- Index classes that are `private`, `protected`, or `private protected`, or nested in a class with one of these access levels.
- Indexes whose required base-class information cannot be obtained from generated metadata or available source.
  This can happen when a base class is in a compiled assembly built with a client version that does not include the RavenDB analyzers.
  See [Distribution](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/overview.md#distribution).

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

Add a constructor (or update the existing one) that assigns the `Map` property.

If the class is only a base for other indexes, declare it `abstract`.

---

### Before (triggers RVN004)

```csharp
// Triggers RVN004: Map is never assigned.
public class Orders_ByCompany : AbstractIndexCreationTask<Order>
{
}
```

### 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}

RVN004 does not verify that every constructor or execution path assigns `Map`.

**RVN004 can be suppressed even when `Map` remains unset:**

- An assignment in any constructor counts, including a base constructor that the index never calls.
- An assignment inside a condition counts even when the condition prevents it from executing.
- An assignment inside a lambda or local function nested in a checked constructor or method counts even if the lambda or local function is never invoked.
- Calls to methods are matched by name only. An assignment in another overload with the same name can therefore suppress RVN004 even when that overload is never called.

**RVN004 can be reported even when `Map` is assigned at runtime:**

- An assignment made only in a property setter is not detected, even if the constructor sets that property.
- An assignment made through another reference, such as `index.Map = ...`, is not recognized.
- A helper method defined in a base class from a referenced project is not followed when only a derived constructor calls it.
  `Map` assignments reachable from that base class's own constructors still count through its generated index metadata.

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

- [RVN001](https://docs.ravendb.net/7.2/client-api/csharp-code-analyzers/RVN001.md)  
  Fires when `Map` is assigned in a method rather than a constructor.  
  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)  
  Equivalent rule for multi-map indexes.

## 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)
