Fixed: "The name 'Teams' does not exist in the current context" with [TeamsExtension] in the Microsoft 365 Agents SDK
The Microsoft 365 Agents SDK's documentation says that marking an agent class with [TeamsExtension] gives it a Teams property. I wrote Teams.TaskModules.OnFetch(...), and the build stopped with error CS0103: The name 'Teams' does not exist in the current context. The property exists: it's called TeamsExtension.
What I Was Doing
I was building an agent that opens Microsoft Teams dialogs, with the Microsoft 365 Agents SDK 1.9.205 on .NET 10. Dialogs belong to the Teams extension, which comes in the Microsoft.Agents.Extensions.MSTeams package, so I added it:
dotnet add package Microsoft.Agents.Extensions.MSTeams --version 1.9.205
The SDK's documentation for TeamsExtensionAttribute, in its XML comments and on Microsoft Learn, describes the setup: Marks an AgentApplication subclass to automatically receive a generated Teams property of type TeamsAgentExtension. Its example uses _ = Teams;. So the class got the attribute and the partial keyword, and the constructor used Teams:
[TeamsExtension]
public partial class SupplyDeskAgent : AgentApplication
{
public SupplyDeskAgent(AgentApplicationOptions options, ILogger<SupplyDeskAgent> logger) : base(options)
{
// ...
Teams.TaskModules.OnFetch("request", OpenFormAsync);
Teams.TaskModules.OnSubmit("review", ReviewAsync);
Teams.TaskModules.OnSubmit("back", BackAsync);
Teams.TaskModules.OnSubmit("send", SendAsync);
Teams.TaskModules.OnSubmit("cancel", CancelAsync);
}
}
What I Expected
A build that succeeds, with Teams generated into the other part of the partial class.
What I Got
Five errors, one for each line that used Teams:
dotnet build
Determining projects to restore...
All projects are up-to-date for restore.
/Users/you/SupplyDesk/SupplyDeskAgent.cs(25,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(26,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(27,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(28,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(29,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(93,52): warning CS8625: Cannot convert null literal to non-nullable reference type. [/Users/you/SupplyDesk/SupplyDesk.csproj]
Build FAILED.
/Users/you/SupplyDesk/SupplyDeskAgent.cs(93,52): warning CS8625: Cannot convert null literal to non-nullable reference type. [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(25,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(26,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(27,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(28,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
/Users/you/SupplyDesk/SupplyDeskAgent.cs(29,9): error CS0103: The name 'Teams' does not exist in the current context [/Users/you/SupplyDesk/SupplyDesk.csproj]
1 Warning(s)
5 Error(s)
Time Elapsed 00:00:00.83

The warning in the same output is a separate problem, with its own post: Fixed: warning CS8625: Cannot convert null literal to non-nullable reference type.
What I Checked
Whether anything was generated at all. The C# compiler can write the code that source generators produce into the obj folder. Building once more with EmitCompilerGeneratedFiles turned on, and --no-incremental so that the compiler actually runs:
dotnet build --no-incremental -p:EmitCompilerGeneratedFiles=true
That left one file under obj/Debug/net10.0/generated/Microsoft.Agents.Core.Analyzers/:
// <auto-generated />
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable disable
namespace SupplyDesk
{
partial class SupplyDeskAgent
{
/// <summary>
/// Provides access to <see cref="Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension"/> agent features.
/// </summary>
public global::Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension TeamsExtension { get; private set; }
protected override void ConfigureExtensions()
{
base.ConfigureExtensions();
TeamsExtension = new global::Microsoft.Agents.Extensions.MSTeams.TeamsAgentExtension(this);
RegisterExtension(TeamsExtension, _ => { });
}
}
}

The generator worked. It named the property TeamsExtension.
Why that name. The generator is AgentExtensionSourceGenerator, in the Microsoft.Agents.Core.Analyzers that comes with the SDK. In the SDK's source, it builds the name from the extension's type: it removes AgentExtension from the end of TeamsAgentExtension, which leaves Teams, and then adds Extension. Its own summary gives the example: TeamsAgentExtension → TeamsExtension.
Whether this is still the case. The same generator and the same Teams documentation are in 1.10.66-beta and on the SDK's main branch. I reported the difference to the SDK's team: microsoft/Agents-for-net#1108.
Why It Happens
The documentation and the generator disagree. The XML comments of TeamsExtensionAttribute and of the TeamsAgentExtension constructor, and the Microsoft Learn pages built from them, say Teams. The generator writes TeamsExtension. Code written from the docs uses a name that doesn't exist, which is what CS0103 says.
The Fix
Use the name the generator writes:
TeamsExtension.TaskModules.OnFetch("request", OpenFormAsync);
TeamsExtension.TaskModules.OnSubmit("review", ReviewAsync);
TeamsExtension.TaskModules.OnSubmit("back", BackAsync);
TeamsExtension.TaskModules.OnSubmit("send", SendAsync);
TeamsExtension.TaskModules.OnSubmit("cancel", CancelAsync);
After the Fix
dotnet build
Determining projects to restore...
All projects are up-to-date for restore.
SupplyDesk -> /Users/you/SupplyDesk/bin/Debug/net10.0/SupplyDesk.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.26

The routes registered through TeamsExtension worked in Teams: the agent's dialog opened from its card, and each of its buttons reached its handler.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing Teams. as the documentation shows | error CS0103: The name 'Teams' does not exist in the current context | Write TeamsExtension. |
Leaving out partial | error MAA001: '...' must be declared as 'partial' to use an AgentExtension attribute | Declare the class partial |
| Looking for the generated file after a build that changed nothing | No .g.cs file appears | Add --no-incremental |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
CS0103 ... 'Teams' on every use | The property is named TeamsExtension | Rename the uses |
CS0103 ... 'TeamsExtension' | The class has no [TeamsExtension] | Add the attribute to your AgentApplication subclass |
MAA001 | The class isn't partial | Add partial |
FAQ
When is the TeamsExtension property created?
When the agent is constructed. The generated ConfigureExtensions creates and registers it, and the generator's summary calls it assigned during construction. The attribute's documentation says lazily initialized and registered with the application on first access, which is the other point the GitHub issue raises.
Can I name the property myself?
Not with the attribute: the generator picks the name. Without the attribute, the TeamsAgentExtension constructor creates the extension yourself; its documentation says to use it only when manually registering the extension.
Do route attributes need the property?
No. Routes declared with the extension's attributes, such as [TeamsTaskFetchRoute], register without your code touching the property. Microsoft's dialog sample uses only attributes, so its code never mentions the property.
Conclusion
[TeamsExtension] on a partial AgentApplication class generates a property named TeamsExtension, not Teams as the SDK's documentation says. Write TeamsExtension.TaskModules, TeamsExtension.MessageExtensions and so on, and when a generated name is in doubt, build with -p:EmitCompilerGeneratedFiles=true and read the file.
Additional Resources
- TeamsExtensionAttribute Class, on Microsoft Learn.
- TeamsAgentExtension Class, on Microsoft Learn.
- Source generators, on Microsoft Learn.
- microsoft/Agents-for-net#1108: the report of the difference.
