Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于cloud pubsub运行c#示例项目时的依赖性问题_C#_.net_Nuget_Google Cloud Pubsub - Fatal编程技术网

基于cloud pubsub运行c#示例项目时的依赖性问题

基于cloud pubsub运行c#示例项目时的依赖性问题,c#,.net,nuget,google-cloud-pubsub,C#,.net,Nuget,Google Cloud Pubsub,我正在将Google Cloud PubSub集成到一个示例c#项目中,我是一个c#新手,因为这可能是我公司唯一一个c#项目,因为我需要与用c#编写的游戏集成。 我使用NuGet安装了Google.Cloud.PubSub.V1.0.0-beta13,安装成功,但是当我尝试运行使用文档创建的示例代码时,出现以下错误: C:/Users/MyUser/RiderProjects/TestConsole/TestConsole/bin/Debug/TestConsole.exe Unhandled

我正在将Google Cloud PubSub集成到一个示例c#项目中,我是一个c#新手,因为这可能是我公司唯一一个c#项目,因为我需要与用c#编写的游戏集成。 我使用NuGet安装了Google.Cloud.PubSub.V1.0.0-beta13,安装成功,但是当我尝试运行使用文档创建的示例代码时,出现以下错误:

C:/Users/MyUser/RiderProjects/TestConsole/TestConsole/bin/Debug/TestConsole.exe

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task) in C:\Users\jon\Test\Projects\gax-dotnet\releasebuild\src\Google.Api.Gax\TaskExtensions.cs:line 48
   at Google.Api.Gax.Grpc.ChannelPool.GetChannel(ServiceEndpoint endpoint) in C:\Users\jon\Test\Projects\gax-dotnet\releasebuild\src\Google.Api.Gax.Grpc\ChannelPool.cs:line 92
   at Google.Cloud.PubSub.V1.PublisherClient.Create(ServiceEndpoint endpoint, PublisherSettings settings) in C:\Users\jon\Test\Projects\google-cloud-dotnet\releasebuild\apis\Google.Cloud.PubSub.V1\Google.Cloud.PubSub.V1\PublisherClient.cs:line 558
   at TestConsole.Program.CreateTopic(String projectId, String topicId) in C:\Users\MyUser\RiderProjects\TestConsole\TestConsole\Program.cs:line 11
   at TestConsole.Program.Main(String[] args) in C:\Users\MyUser\RiderProjects\TestConsole\TestConsole\Program.cs:line 32
然后我尝试将Google.Api.Auth降级到1.21.0,但问题转移到“无法加载Google.Api.Gax,Version=1.0.1.0”,然后(如果我继续降级依赖项)在Google.Protobuf 3.2.0.0上,然后在Google.Api.Core 1.24.1上,然后返回到“无法加载Google.Api.Auth 1.21.0”,所以我猜问题出在其他地方了

是什么导致了这种依赖性问题?如果我从Github加载Google Pubsub示例项目,即使packages.config与我的项目中的packages.config相同,我也不会遇到任何问题

这是我的程序。cs:

using Google.Cloud.PubSub.V1;
using Google.Protobuf;

namespace TestConsole
{
    internal class Program
    {

        public static object CreateTopic(string projectId, string topicId)
        {
            var publisher = PublisherClient.Create();

            var topicName = new TopicName(projectId, topicId);
            var message = new PubsubMessage
            {
                // The data is any arbitrary ByteString. Here, we're using text.
                Data = ByteString.CopyFromUtf8("Hello Cloud Pub/Sub!"),
                // The attributes provide metadata in a string-to-string
                // dictionary.
                Attributes =
                {
                    { "description", "Simple text message" }
                }
            };
            publisher.Publish(topicName, new[] { message });
            return 0;
        }


        public static void Main(string[] args)
        {
            CreateTopic("MyProjectID", "MyProjectTopic");
        }
    }
}
和my packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Google.Api.CommonProtos" version="1.0.0" targetFramework="net452" />
  <package id="Google.Api.Gax" version="1.0.1" targetFramework="net452" />
  <package id="Google.Api.Gax.Grpc" version="1.0.1" targetFramework="net452" />
  <package id="Google.Apis" version="1.24.1" targetFramework="net452" />
  <package id="Google.Apis.Auth" version="1.24.1" targetFramework="net452" />
  <package id="Google.Apis.Core" version="1.24.1" targetFramework="net452" />
  <package id="Google.Cloud.Iam.V1" version="1.0.0-beta09" targetFramework="net452" />
  <package id="Google.Cloud.PubSub.V1" version="1.0.0-beta09" targetFramework="net452" />
  <package id="Google.Protobuf" version="3.2.0" targetFramework="net452" />
  <package id="Grpc.Auth" version="1.4.0" targetFramework="net452" />
  <package id="Grpc.Core" version="1.4.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
  <package id="System.Interactive.Async" version="3.1.1" targetFramework="net452" />
  <package id="System.Net.Http" version="4.3.1" targetFramework="net425" />
  <package id="Zlib.Portable.Signed" version="1.11.0" targetFramework="net452" />
</packages>

我使用Rider 2017.1.1运行我的项目,并在.NET framework 4.5.2上运行它

请注意,我已经知道,一个非常类似的问题已经发布在这个URL上,但由于我的“声誉”很低,我不能对此发表评论(你知道,我通常会阅读文档,搜索已经回答的问题,并试图避免创建重复的问题,这就是为什么我没有在这个网站上建立很高的声誉)提出这个问题的人自己解决了这个问题,却不知道如何解决。 答案是:

…如果您通过NuGet管理所有依赖项,我希望一切正常 -它应该为您添加程序集绑定重定向


在我看来,我已经这样做了。

尝试一个新的开始:在Nuget Package Manager控制台中运行以下命令,清除所有Google依赖项:

PM> get-package | where {$_.Id -like 'Google*'} | % { uninstall-package -Force $_.Id -ProjectName $_.ProjectName}
然后再次安装PubSub:

PM> install-package Google.Cloud.PubSub.V1 -pre

在Jeffrey的建议之后,我开始用Visual Studio执行我的项目,我注意到它不会触发依赖项错误。 所以,这似乎是骑手的问题。
我可能会要求JetBrains澄清,但如果有人有更好的答案,请发表您的意见。

嗨!您是否尝试了链接问题的公认答案中的最后一个建议?“[…]或者只是在应用程序和库中添加对Google.Cloud.PubSub.V1的引用,此时NuGet将为您执行所有依赖项处理。”我注意到的另一个细节是您在问题中提到了
beta13
,但
beta09
packages.config
文件中引用。可能有版本不匹配的地方吗?嗨@MarcelloRomani我尝试了不同的版本,所以不匹配可能是我尝试处理事情的不同方式的遗留问题。另外,我已经在应用程序中添加了引用,但我不知道在库中添加它意味着什么。您好,感谢您提到Nuget Package Manager控制台,在学习教程时,我总是使用Powershell,因为我不知道它的存在,也因为我没有在Rider中找到它。您的回答并没有直接解决问题,但通过使用VisualStudio运行该项目,我能够使其正常工作。可能是Rider上有一个bug(它仍然不起作用)?