googleapis / google-cloud-dotnet

Google Cloud Client Libraries for .NET
https://cloud.google.com/dotnet/docs/reference/
Apache License 2.0
932 stars 365 forks source link

Could not load type 'System.Collections.Generic.IAsyncEnumerable'1' from assembly 'System.Interactive.Async' #3081

Closed seunghun-kim closed 5 years ago

seunghun-kim commented 5 years ago

Environment details

Issue details

I'm trying to use firestore db as my board test result storage. In order to test it's well functioning, I've modified sample code a bit. Here's my code.

FirestoreDb db = FirestoreDb.Create("aavm-e4218");

// Create a document with a random ID in the "users" collection.
CollectionReference collection = db.Collection("TestData");
TestData temp = new TestData() {
    Serial = "TEST2",
    FrontCam = true,
    BackCam = true,
    LeftCam = true,
    RightCam = true,

    FrontLin = true,
    BackLin = true,
    LeftLin = true,
    RightLin = true,

    Can = true,

    OperationOn12V = true,
    CurrentOn12V = 0.678,
    OperationOn24V = true,
    CurrentOn24V = 0.456,

    MinVoltage = true,
    MaxVoltage = true
};
DocumentReference document = await collection.AddAsync(temp);

// A DocumentReference doesn't contain the data - it's just a path.
// Let's fetch the current document.
DocumentSnapshot snapshot = await document.GetSnapshotAsync();

// We can access individual fields by dot-separated path
Console.WriteLine(snapshot.GetValue<string>("Serial"));
Console.WriteLine(snapshot.GetValue<double>("CurrentOn12V"));
Console.WriteLine(snapshot.GetValue<bool>("Can"));

// Query the collection for all documents where doc.Born < 1900.
Query query = collection.WhereEqualTo("Serial", "TEST2");
QuerySnapshot querySnapshot = await query.GetSnapshotAsync();
foreach (DocumentSnapshot queryResult in querySnapshot.Documents) {
    string serial = queryResult.GetValue<string>("Serial");
    double current = queryResult.GetValue<double>("CurrentOn12V");
    bool can = queryResult.GetValue<bool>("Can");
    Console.WriteLine($"{serial} {current} {can}");
}

In case if you need it, there's TestData class below:

[FirestoreData]
public class TestData {
    [FirestoreProperty]
    public string Serial { get; set; }

    [FirestoreProperty]
    public bool FrontCam { get; set; }

    [FirestoreProperty]
    public bool BackCam { get; set; }

    [FirestoreProperty]
    public bool LeftCam { get; set; }

    [FirestoreProperty]
    public bool RightCam { get; set; }

    [FirestoreProperty]
    public bool FrontLin { get; set; }

    [FirestoreProperty]
    public bool BackLin { get; set; }

    [FirestoreProperty]
    public bool LeftLin { get; set; }

    [FirestoreProperty]
    public bool RightLin { get; set; }

    [FirestoreProperty]
    public bool Can { get; set; }

    [FirestoreProperty]
    public bool OperationOn12V { get; set; }

    [FirestoreProperty]
    public double CurrentOn12V { get; set; }

    [FirestoreProperty]
    public bool OperationOn24V { get; set; }

    [FirestoreProperty]
    public double CurrentOn24V { get; set; }

    [FirestoreProperty]
    public bool MinVoltage { get; set; }

    [FirestoreProperty]
    public bool MaxVoltage { get; set; }
}

It works fine just before DocumentSnapshot snapshot = await document.GetSnapshotAsync();. But GetSnapshotAsync() throws exception:

Could not load type 'System.Collections.Generic.IAsyncEnumerable'1' from assembly 'System.Interactive.Async, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263'

And here's details.

System.TypeLoadException
  HResult=0x80131522
  Message='System.Interactive.Async, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' 어셈블리에서 'System.Collections.Generic.IAsyncEnumerator`1' 형식을 로드할 수 없습니다.
  Source=Google.Cloud.Firestore
  StackTrace:
   at Google.Cloud.Firestore.FirestoreDb.<<GetDocumentSnapshotsAsync>b__33_0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Google.Cloud.Firestore.FirestoreDb.<GetDocumentSnapshotsAsync>b__33_0(BatchGetDocumentsRequest req, CallSettings settings)
   at Google.Cloud.Firestore.RetryHelper.<Retry>d__0`2.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Firestore.FirestoreDb.<GetDocumentSnapshotsAsync>d__33.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Firestore.DocumentReference.<GetSnapshotAsync>d__26.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at RealtimeDatabase_Test.Program.<RunFireStoreService>d__1.MoveNext() in D:\dwcy2\Documents\Infoworks\Project\AAVM\A40i_Tester\RealtimeDatabase_Test\Program.cs:line 46

I can't find out what's the problem. Please give me some help.

Steps to reproduce

  1. Make a C# Console Application named "RealtimeDatabase_Test"
  2. Install Google.Cloud.Firestore 1.0.0-beta20 in nuget.
  3. Make new firestore db in firebase.
  4. Run the code below.
    
    using Google.Cloud.Firestore;
    using System;

namespace RealtimeDatabase_Test { class Program { static void Main(string[] args) { RunFireStoreService(); }

    static async void RunFireStoreService() {
        FirestoreDb db = FirestoreDb.Create(/////////////////YOUR_DB_NAME///////////////////);

        // Create a document with a random ID in the "users" collection.
        CollectionReference collection = db.Collection("TestData");
        TestData temp = new TestData() {
            Serial = "TEST2",
            FrontCam = true,
            BackCam = true,
            LeftCam = true,
            RightCam = true,

            FrontLin = true,
            BackLin = true,
            LeftLin = true,
            RightLin = true,

            Can = true,

            OperationOn12V = true,
            CurrentOn12V = 0.678,
            OperationOn24V = true,
            CurrentOn24V = 0.456,

            MinVoltage = true,
            MaxVoltage = true
        };
        DocumentReference document = await collection.AddAsync(temp);

        // A DocumentReference doesn't contain the data - it's just a path.
        // Let's fetch the current document.
        DocumentSnapshot snapshot = await document.GetSnapshotAsync();

        // We can access individual fields by dot-separated path
        Console.WriteLine(snapshot.GetValue<string>("Serial"));
        Console.WriteLine(snapshot.GetValue<double>("CurrentOn12V"));
        Console.WriteLine(snapshot.GetValue<bool>("Can"));

        // Query the collection for all documents where doc.Born < 1900.
        Query query = collection.WhereEqualTo("Serial", "TEST2");
        QuerySnapshot querySnapshot = await query.GetSnapshotAsync();
        foreach (DocumentSnapshot queryResult in querySnapshot.Documents) {
            string serial = queryResult.GetValue<string>("Serial");
            double current = queryResult.GetValue<double>("CurrentOn12V");
            bool can = queryResult.GetValue<bool>("Can");
            Console.WriteLine($"{serial} {current} {can}");
        }
    }
}

[FirestoreData]
public class TestData {
    [FirestoreProperty]
    public string Serial { get; set; }

    [FirestoreProperty]
    public bool FrontCam { get; set; }

    [FirestoreProperty]
    public bool BackCam { get; set; }

    [FirestoreProperty]
    public bool LeftCam { get; set; }

    [FirestoreProperty]
    public bool RightCam { get; set; }

    [FirestoreProperty]
    public bool FrontLin { get; set; }

    [FirestoreProperty]
    public bool BackLin { get; set; }

    [FirestoreProperty]
    public bool LeftLin { get; set; }

    [FirestoreProperty]
    public bool RightLin { get; set; }

    [FirestoreProperty]
    public bool Can { get; set; }

    [FirestoreProperty]
    public bool OperationOn12V { get; set; }

    [FirestoreProperty]
    public double CurrentOn12V { get; set; }

    [FirestoreProperty]
    public bool OperationOn24V { get; set; }

    [FirestoreProperty]
    public double CurrentOn24V { get; set; }

    [FirestoreProperty]
    public bool MinVoltage { get; set; }

    [FirestoreProperty]
    public bool MaxVoltage { get; set; }
}

}



I hope I could find answer soon. Thank you a lot.
jskeet commented 5 years ago

I'd expect System.Interactive.Async to be installed via NuGet dependencies.

Please could you give details of exactly how you're creating the console application? What kind of project file are you using? (If you could include the project file itself, that would be great.)

Note that to reproduce this, we shouldn't need your TestData type at all - just creating a document with an anonymous type should be fine. For example, here's a console app which works fine for me (targeting netcoreapp2.1), but which sounds like it would still fail for you:

using Google.Cloud.Firestore;
using System;
using System.Threading.Tasks;

namespace Issue3081
{
    class Program
    {
        static async Task Main(string[] args)
        {
            FirestoreDb db = FirestoreDb.Create(args[0]);
            CollectionReference collection = db.Collection("TestData");
            DocumentReference document = await collection.AddAsync(new { Name = "Test doc", Score = 20 });
            DocumentSnapshot snapshot = await document.GetSnapshotAsync();
            Console.WriteLine(snapshot.GetValue<string>("Name"));
            Console.WriteLine(snapshot.GetValue<long>("Score"));
        }
    }
}

Here's my csproj file for that:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <LangVersion>7.3</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Google.Cloud.Firestore" Version="1.0.0-beta20" />
  </ItemGroup>

</Project>
jskeet commented 5 years ago

I've just tried the same thing with .NET 4.7.2 using an "old style" project file, and that worked fine too.

Could you give details about what's in the output directory that you're executing from?

seunghun-kim commented 5 years ago

I uninstalled System.Interactive.Async and reinstalled Google.Cloud.Firestore. That solved my issue. Thanks.