Google.Apis.Auth 1.46.0.0 is installed but then being asked for multiple versions

0

I am able to get Firestore access through winforms by itself and it works. however, if I try to access Firestore through an external command, I get an error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Google.Apis.Auth, Version=1.44.1.0, Culture=neutral, PublicKeyToken=XXXXXXXXXX' or one of its dependencies. The system cannot find the file specified.'

The weird part is that I have Google.Apis.Auth, Version=1.46.0.0 as a reference.

If I change my reference version to 1.44.1.0, then it asks me to change the reference version to 1.21.0.0

How can I make this work?

Here is my code:

App.cs

#region Namespaces
using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Reflection;
using System.Windows.Media.Imaging;
using Google.Cloud.Firestore;
using System.Windows.Forms;
#endregion

namespace testformsFirestore
{
    class App : IExternalApplication
    {
        public Result OnStartup(UIControlledApplication a)
        {

            RibbonPanel panel = ribbonPanel(a);
            string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
            PushButton button = panel.AddItem(new PushButtonData("testformsFirestore" ,
                "testformsFirestore Button", thisAssemblyPath, "testformsFirestore.Command")) as PushButton; 

            button.ToolTip = "this is a simple tooltip";
            var globePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Corvette.PNG");
            
            Uri uriImage = new Uri(globePath);
            BitmapImage largeImage = new BitmapImage(uriImage);
            button.LargeImage = largeImage;

            

            a.ApplicationClosing += a_ApplicationClosing;

            // Set application idling
            a.Idling += a_Idling;


            return Result.Succeeded;
        }

        void a_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
        {

        }

        void a_ApplicationClosing(object sender, Autodesk.Revit.UI.Events.ApplicationClosingEventArgs e)
        {
            throw new NotImplementedException();
        }


        public RibbonPanel ribbonPanel(UIControlledApplication a)
        {
            string tab = "My test tab";
            RibbonPanel ribbonPanel = null;
            try
            {
                a.CreateRibbonTab(tab);
            }
            catch { }
            try
            {
                RibbonPanel panel = a.CreateRibbonPanel(tab, "test");
            }
            catch { }

            List<RibbonPanel> panels = a.GetRibbonPanels(tab);
            foreach (RibbonPanel p in panels)
            {
                if (p.Name == "test")
                {
                    ribbonPanel = p;
                }
            }
            return ribbonPanel;
        }


        public Result OnShutdown(UIControlledApplication a)
        {
            return Result.Succeeded;
        }
    }
}

Command.cs

#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace testformsFirestore
{
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Form1 form1 = new Form1();


            using (Transaction tx = new Transaction(doc, "Transaction Name"))
            {
                try
                {
                    tx.Start();

                    // Code goes here.
                    form1.Show();


                    tx.Commit();
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                    tx.RollBack();
                }
            }

            return Result.Succeeded;
        }
    }
}

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Google.Cloud.Firestore;

namespace testformsFirestore
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string path = "\\\\Mac\\Home\\Desktop\\testformsFirestore\\testFormsFirestore\\bin\\Debug\\myProjectJsonPath.json";
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
            
            FirestoreDb db = FirestoreDb.Create("myProjectId");

            CollectionReference collection = db.Collection("Users");

            getSnapshot();
            async void getSnapshot()
            {
                // A CollectionReference is a Query, so we can just fetch everything
                QuerySnapshot allUsers = await collection.GetSnapshotAsync();
                foreach (DocumentSnapshot document in allUsers.Documents)
                {

                    MessageBox.Show(document.GetValue<string>("username").ToString()); ;
                    
                }

            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

app.config

        <assemblyIdentity name="Google.Apis.Auth" publicKeyToken="XXXXXXXXXX" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.46.0.0" newVersion="1.46.0.0" />
      </dependentAssembly>

StackTrace

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXX' or one of its dependencies. The system cannot find the file specified.
  Source=Google.Api.Gax.Grpc
  StackTrace:
   at Google.Api.Gax.Grpc.ChannelPool.<CreateChannelCredentialsUncached>d__5.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Google.Api.Gax.Grpc.ChannelPool.CreateChannelCredentialsUncached()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task)
   at Google.Api.Gax.Grpc.ChannelPool.GetChannel(GrpcAdapter grpcAdapter, String endpoint, GrpcChannelOptions channelOptions)
   at Google.Api.Gax.Grpc.ClientBuilderBase`1.CreateCallInvoker()
   at Google.Cloud.Firestore.V1.FirestoreClientBuilder.BuildImpl()
   at Google.Cloud.Firestore.FirestoreDbBuilder.Build()
   at DockableDialog.RegisterDockableWindow.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in \\Mac\Home\Desktop\Revit-API---C-\DockableWPFPane2021\DockablePane2021\Ribbon.cs:line 137
   at apiManagedExecuteCommand(AString* assemblyName, AString* className, AString* vendorDescription, MFCApp* pMFCApp, DBView* pDBView, AString* message, Set<ElementId\,std::less<ElementId>\,tnallc<ElementId> >* ids, Map<AString\,AString\,std::less<AString>\,tnallc<std::pair<AString const \,AString> > >* data, AString* exceptionName, AString* exceptionMessage)

Log

'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\testForms.dll'. 
System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='6995273'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='Autodesk.Internal.Windows.ToolTip'; TargetElement.HashCode='54242802'; TargetElement.Type='Autodesk.Internal.Windows.ToolTip'
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Cloud.Firestore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Cloud.Firestore.V1.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ValueTuple\v4.0_4.0.0.0__cc7b13ffcd2ddd51\System.ValueTuple.dll'. Module was built without symbols.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Api.Gax.Grpc.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Api.Gax.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Grpc.Core.Api.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Api.Gax.Grpc.GrpcCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Apis.Auth.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Google.Apis.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Revit.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\myName\AppData\Roaming\Autodesk\Revit\Addins\2021\Grpc.Auth.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Could not load file or assembly 'Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXX' or one of its dependencies. The system cannot find the file specified.
c#
winforms
google-cloud-firestore
revit-api
revitpythonshell
asked on Stack Overflow Jun 28, 2020 by Cflux • edited Jul 2, 2020 by Cflux

1 Answer

0

Notice that you set the environment variable for authentication and create the Firestore client (FirestoreDb db = FirestoreDb.Create("myProjectId");) within the method when the button is clicked.

        private void button1_Click(object sender, EventArgs e)
        {

            string path = "\\\\Mac\\Home\\Desktop\\testformsFirestore\\testFormsFirestore\\bin\\Debug\\myProjectJsonPath.json";
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
            
            FirestoreDb db = FirestoreDb.Create("myProjectId");

            CollectionReference collection = db.Collection("Users");

Set the environment variable:

string path = "\\\\Mac\\Home\\Desktop\\testformsFirestore\\testFormsFirestore\\bin\\Debug\\myProjectJsonPath.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path)

and make the initialization of the client:

FirestoreDb db = FirestoreDb.Create("myProjectId");
CollectionReference collection = db.Collection("Users");

in a previous step within your application.

answered on Stack Overflow Jun 29, 2020 by Daniel Ocando

User contributions licensed under CC BY-SA 3.0