【问题标题】:Google.Apis.Auth 1.46.0.0 is installed but then being asked for multiple versionsGoogle.Apis.Auth 1.46.0.0 已安装,但随后被要求提供多个版本
【发布时间】:2020-10-18 23:42:26
【问题描述】:

我可以自己通过 winforms 获得 Firestore 访问权限,并且可以正常工作。但是,如果我尝试通过外部命令访问 Firestore,则会收到错误消息:

System.IO.FileNotFoundException: '无法加载文件或程序集 'Google.Apis.Auth, Version=1.44.1.0, Culture=neutral, PublicKeyToken=XXXXXXXXXX' 或其依赖项之一。系统找不到指定的文件。'

奇怪的是我有Google.Apis.Auth, Version=1.46.0.0 作为参考。

如果我将参考版本更改为1.44.1.0,那么它会要求我将参考版本更改为1.21.0.0

我怎样才能做到这一点?

这是我的代码:

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>

堆栈跟踪

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)

日志

'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


    【解决方案1】:

    请注意,您为身份验证设置了环境变量,并在单击按钮时在方法中创建了 Firestore 客户端 (FirestoreDb db = FirestoreDb.Create("myProjectId");)。

            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");
    

    设置环境变量:

    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");
    

    在您的应用程序的上一步中。

    【讨论】:

    • 所以我尝试将它放在调用Form1.cs的Command.cs文件中,然后我也尝试将它放在调用Command.cs的App.cs中,这是我可以放置的最早步骤在但我仍然得到相同的结果。我将发布我的 App.cs 代码。
    • 如果是这种情况,我认为它们可能是关于如何在您的计算机上安装软件包及其依赖项的具体问题。您是否尝试过采取任何提到的措施here。也许following video 也有帮助。
    • 所以我只是尝试按照视频进行操作,该视频让我删除了现有引用并将其重新路径到我项目调试文件中的副本。它仍然要求1.44.1.01.21.0.0 的不同版本。我会尝试在您的其他链接中提到的依赖walker。
    • 所以我尝试了另一条路线。没有运气。我已经更新了我的问题以包含堆栈跟踪。我还发现,我认为是问题的根源。 Grpc.Auth 的依赖项之一是 &gt;= Google.Apis.Auth version 1.21.0.0。这只是一个猜测。我也走上了查看绑定重定向的路线,但我也没有任何运气。
    • 另外,我认为您最好从帖子中删除 PublicKeyToken。因为一般来说,通过任何公共论坛共享密钥、令牌、密码等都不是一个好主意。
    猜你喜欢
    • 2021-09-24
    • 2019-05-04
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 2012-01-27
    • 1970-01-01
    相关资源
    最近更新 更多