[CSHARP-4822] C# driver with .NET 7.0 & Linux doesn't work Created: 30/Oct/23  Updated: 24/Nov/23  Resolved: 24/Nov/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.22.0
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Martin B Assignee: Boris Dogadov
Resolution: Gone away Votes: 0
Labels: drivers
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive MongoSample.zip     Text File stacktrace.txt    

 Description   

Summary

I get System.MissingMethodException when trying to connect to MongoDB instance.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Driver version 2.22.0

How to Reproduce

Run following code in .NET 7 on linux-x64

var client = new MongoClient("mongodb://my-mongodb-server:27017/");
var databases = client.ListDatabases().ToList();

publish using following publish profile:

<?xml version="1.0" encoding="utf-8"?>
<Project>
    <PropertyGroup>
        <Configuration>Release</Configuration>
        <PublishDir>bin\publish\linux-x64\</PublishDir>
        <PublishProtocol>FileSystem</PublishProtocol>
        <_TargetId>Folder</_TargetId>
        <TargetFramework>net7.0</TargetFramework>
        <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
        <SelfContained>true</SelfContained>
        <PublishSingleFile>true</PublishSingleFile>
        <PublishTrimmed>true</PublishTrimmed>
    </PropertyGroup>
</Project>

Additional Background

install@REDACTED:~$ uname -a
Linux REDACTED 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux



 Comments   
Comment by PM Bot [ 24/Nov/23 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to reopen this ticket if you're still experiencing the issue, and add a comment if you're able to provide more information.

Comment by PM Bot [ 16/Nov/23 ]

Hi mbalous@outlook.com! CSHARP-4822 is awaiting your response.

If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks!

Comment by Boris Dogadov [ 08/Nov/23 ]

Hi mbalous@outlook.com , thanks for bringing this issue to our attention. We've reproduced the failure in trimmed mode.
Our driver is not trim-compatible, we'll be addressing this issue in CSHARP-4840.

As a workaround you could opt-out the driver from trimming.
Not sure if there is a better way, but one way to do so is setting TrimMode to partial and specifying all trimmed assemblies manually by TrimmableAssembly item.

Comment by Martin B [ 30/Oct/23 ]

Looks like it's related to trimming:
ConfigurationManager is not trim compatible · Issue #49062 · dotnet/runtime (github.com)

Regular .NET 7 without trimming on linux-x64 works

Comment by PM Bot [ 30/Oct/23 ]

Hi mbalous@outlook.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:49:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.