microsoftgraph / microsoftgraph/microsoft-graph-comms-samples
ICommunicationsClient.CreateMediaSession causing Access Violation when running as a Windows Service
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 253
- Forks
- 275
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 1
Description
Describe the issue
Application crashes with access violation when calling CreateMediaSession on the CommunicationClient if being run as a windows service.
I get the following logs in event viewer:
This is the exception caught by attaching the Visual Studio debugger:
Code Snippet
Around the exception site:
IMediaSession mediaSession = Guid.TryParse(call.Id, out Guid callId)
? CreateLocalMediaSession(callId)
: CreateLocalMediaSession();
try
{
_logger.LogInformation("Attempting to answer call {CallId} with scenario {ScenarioId}", call.Id, call.ScenarioId);
await call.AnswerAsync(mediaSession);
_logger.LogInformation("Answered call {CallId} successfully", call.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to answer call {CallId} with scenario {ScenarioId}", call.Id, call.ScenarioId);
}
private ILocalMediaSession CreateLocalMediaSession(Guid mediaSessionId = default)
{
try
{
_logger.LogInformation("Creating media session {MediaSessionId}", mediaSessionId);
return _communicationsClient.CreateMediaSession(
new AudioSocketSettings
{
StreamDirections = StreamDirection.Recvonly,
// Note! Currently, the only audio format supported when receiving unmixed audio is Pcm16K
SupportedAudioFormat = AudioFormat.Pcm16K,
ReceiveUnmixedMeetingAudio = false,
},
new VideoSocketSettings
{
StreamDirections = StreamDirection.Inactive
},
mediaSessionId: mediaSessionId );
}
catch (Exception ex)
{
_logger.LogError(ex, "Something went wrong when creating a local media session.");
throw;
}
}
Graph SDK (please complete the following information):
<PackageReference Include="Microsoft.Graph.Communications.Calls" Version="1.2.0.7270" />
<PackageReference Include="Microsoft.Graph.Communications.Calls.Media" Version="1.2.0.7270" />
<PackageReference Include="Microsoft.Graph.Communications.Client" Version="1.2.0.7270" />
<PackageReference Include="Microsoft.Skype.Bots.Media" Version="1.27.0.2-alpha" />
Call ID
Both of the following times are UTC +1
[16:06:54][Information] Creating call record for call 6d1f5e00-6c52-49f5-9dd5-fc6102c395cb
[16:11:38][Information] Creating call record for call 791f5f00-c6f4-49ef-8cb6-cf8176756ab7
Logs
The ILoggers log out to a file and the last log in the file each time it crashes is something similar to this, implying that the application code doesn't execute past CreateMediaSession as the Attempting to answer call log does not appear.
[16:11:38][Information] Creating call record for call 791f5f00-c6f4-49ef-8cb6-cf8176756ab7
The application appears to be hard crashing and not triggering the try/catch so no exceptions are logged.
Additional context
I created the service with the following command:
sc.exe create "Teams Recording Bot Service" binpath="C:\TeamsRecordingBot\TeamsRecordingBot.exe WindowsService"
I tried creating a new local user and added it to the administrator group, and had the windows service login as that. I also tested as the default system user when creating the service, and the network service user.
The bot works without issue when running as a console application, and also appears to work with the windows service services added and then run through Visual Studio. I switch between the two types using a launch argument - which I have confirmed to be working.
[ArgActionMethod, ArgDescription("Starts the application in CLI mode.")]
public static async ValueTask Console()
{
CreateBootstrapLogger();
WebApplicationBuilder builder = await CreateBuilderAsync();
await BuildAndStartAsync(builder);
}
[ArgActionMethod, ArgDescription("Starts the application as a Windows Service.")]
public static async ValueTask WindowsService()
{
CreateBootstrapLogger();
Log.Information("Running as a Windows Service");
WebApplicationBuilder builder = await CreateBuilderAsync();
builder.Services.AddWindowsService(
options => { options.ServiceName = "Teams Recording Bot"; });
builder.Host.UseWindowsService();
await BuildAndStartAsync(builder);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the crash through the WindowsService entry point and compare it with the Console path, focusing on CreateLocalMediaSession and _communicationsClient.CreateMediaSession. Review the listed Microsoft Graph Communications and Skype Bots Media package versions. Done means identifying why the Windows Service path causes the access violation and validating the fix in both service and console modes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- audio-video-rtc, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100