# Checking Text in Code

> Check text without a user interface in a .NET console app with TXSpell and the Core.SDK package: incorrect words, suggestions and the .NET Framework licx entry.

- **Product:** TX Spell .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for WPF > Getting Started > Checking Text in Code
- **1989 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/getting-started/in-code/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/getting-started/in-code/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/getting-started/in-code/llms-full.txt

---

Spell checking doesn't always need a control. A service that validates form fields, a batch job that reports mistakes in texts, or a test that checks generated output only needs to pass a string and read the result. For this, TX Spell .NET has the `TXSpell` class: the same checking and suggestions as the spell checker component, with no dialog, no menu and no window. You build a console application with it and see the incorrect words of a sentence and their suggestions.

### Prerequisites

- Visual Studio on Windows with .NET 8 or higher, or the .NET SDK for the `dotnet` command.
- The setup of TX Spell .NET for WPF 11.0, the full or the trial version, installed on your machine. It provides the package source **Text Control Offline Packages**. See [Installing the Product](https://docs.textcontrol.com/tx-spell-dotnet-wpf/installation/setup/llms-full.txt).

### Create the Project

#### Visual Studio

1. Open Visual Studio and create a new project.
2. Select the project template **Console App** for C# and click **Next**.
3. Enter the project name *InCode* and click **Next**.
4. Select .NET 8 or higher as the **Framework** and click **Create**.

#### .NET CLI

```bash
dotnet new console -n InCode
cd InCode
```

### Install the NuGet Package

The package for code without a user interface is `TXTextControl.TXSpell.Core.SDK`. It contains only *TXSpell.dll* with the `TXSpell` class, and it doesn't depend on TX Text Control or on any other package.

1. Select the project in **Solution Explorer** and choose **Project** > **Manage NuGet Packages...**.
2. Select **Text Control Offline Packages** in the **Package source** list and click **Browse**.
3. Select `TXTextControl.TXSpell.Core.SDK` and click **Install**.

With the .NET CLI, the package source **Text Control Offline Packages** must be configured for NuGet, as [Configuring Package Sources](https://docs.textcontrol.com/tx-spell-dotnet-wpf/installation/nuget/sources/llms-full.txt) describes:

```bash
dotnet add package TXTextControl.TXSpell.Core.SDK
```

The package brings the US English language data and copies it into the output folder when you build: the dictionary in *Dictionaries*, and the hyphenation, language recognition and synonym files in their own folders. It also adds your license file to the project as an embedded resource. [Package Overview](https://docs.textcontrol.com/tx-spell-dotnet-wpf/installation/nuget/packages/llms-full.txt) compares the packages.

### Write the Code

Replace the contents of *Program.cs* with this code:

```csharp
using System;
using TXTextControl.Proofing;

// Create the spell checker and initialize it before first use
TXSpell spell = new TXSpell();
spell.Create();

// The dictionaries loaded from the Dictionaries folder
foreach (Dictionary dictionary in spell.Dictionaries)
{
    Console.WriteLine($"Dictionary: {dictionary.Name} ({dictionary.Language})");
}

string text = "This sentance contains two speling mistakes.";

// Check the text; the incorrect words are listed in IncorrectWords
spell.Check(text);

Console.WriteLine($"{spell.IncorrectWords.Count} incorrect word(s) in: {text}");

foreach (IncorrectWord incorrectWord in spell.IncorrectWords)
{
    // Create at most five suggestions for the incorrect word
    spell.CreateSuggestions(incorrectWord.Text, 5);

    Console.Write($"- {incorrectWord.Text} (position {incorrectWord.Start}):");

    foreach (Suggestion suggestion in spell.Suggestions)
    {
        Console.Write($" {suggestion.Text}");
    }

    Console.WriteLine();
}
```

#### What the Code Does

- [TXSpell](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/llms-full.txt) is the spell checker without a user interface. Its constructor without arguments chooses the dictionary through [Language](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/language-property/llms-full.txt), which is "(Auto)" by default: the dictionary of the environment language, or a close one, otherwise US English.
- [Create](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/create-method/llms-full.txt) initializes the object and must be called before any other member. Without it, `Check` throws an exception that says so.
- [Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/dictionaries-property/llms-full.txt) lists the dictionaries the spell checker loaded. They come from the *Dictionaries* folder next to the application, which is what the default of [DictionariesDirectoryPath](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/dictionariesdirectorypath-property/llms-full.txt), "(Auto)", looks for.
- [Check](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/check-method/llms-full.txt) checks the text. [IncorrectWords](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/incorrectwords-property/llms-full.txt) then holds each incorrect word, with its [Text](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/spelledword/text-property/llms-full.txt) and its [Start](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/spelledword/start-property/llms-full.txt), a position that counts from 0.
- [CreateSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/createsuggestions-method/llms-full.txt) creates suggestions for one word, here at most five. [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell/suggestions-property/llms-full.txt) holds them, closest match first, each with its [Text](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/suggestion/text-property/llms-full.txt).

`TXSpell` doesn't implement `IDisposable`, so it needs no `using` statement.

### Run the Application

Press **Ctrl+F5** in Visual Studio, or run the application with the .NET CLI:

```bash
dotnet run
```

The console shows the dictionary, the two incorrect words with their positions and the suggestions for each:

```text
Dictionary: en_US.dic (en-US)
2 incorrect word(s) in: This sentance contains two speling mistakes.
- sentance (position 5): sentence stance sentience sentences sentenced
- speling (position 27): spelling spieling tippling spewing sling
```

The build reports CA1416 warnings, which say that the methods are supported on Windows. The package targets .NET 8 without an operating system, and TX Spell .NET runs on Windows and Linux without TX Text Control, so the warnings don't stop the application. Add `<NoWarn>CA1416</NoWarn>` to a `PropertyGroup` of the project file to hide them.

### Use It in a .NET Framework Project

In a .NET Framework project, reference *TXSpell.dll* from the *Assembly* folder of the installation instead of installing the package. The license then comes through *licenses.licx*, which needs this entry for `TXSpell`:

```text
TXTextControl.Proofing.TXSpell, TXSpell, Version=11.0.1000.500, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638
```

[Licensing](https://docs.textcontrol.com/tx-spell-dotnet-wpf/troubleshooting/licensing/#licenses-licx-needs-an-entry-for-tx-spell-net) describes the file. The code of the console application stays the same.

### Where to Go From Here

The blog article [Building a Spell Checking Web API in ASP.NET Core](https://www.textcontrol.com/blog/2020/05/15/building-a-spell-checking-web-api-in-aspnet-core/) puts the same class behind a web API, with endpoints for checking, suggestions, synonyms and language detection. Its sample is on GitHub in [TXTextControl.Core.Spell.WebAPI](https://github.com/TextControl/TXTextControl.Core.Spell.WebAPI).

### Next Steps

- [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/suggestions/llms-full.txt): the members of incorrect words and suggestions, and which dictionaries provide them.
- [Ignore Settings](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/ignore-settings/llms-full.txt): decide which words `Check` skips.
- [Loading and Managing Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-wpf/dictionaries/managing/llms-full.txt): add dictionaries of other languages.

---

## Nearby

- **Previous:** [Open the Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/getting-started/richtextbox/dialog/llms-full.txt)
- **Next:** [Spell Checking](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/llms-full.txt)
