google drive api download using .net error - c#

I am trying to download a file from google drive using C# .net. I am using the example code from https://developers.google.com/drive/web/manage-downloads
The code does not compile and giving definition error for IAuthenticator
error CS0234: The type or namespace name 'Authentication' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'IAuthenticator' could not be found (are you missing a using directive or an assembly reference?)
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Authentication;
public static System.IO.Stream DownloadFile(
IAuthenticator authenticator, File file) {
I also tried
service.Files.Get(fileId).Download(myFileStream);
However this is giving error on "file already used by process"
Has anyone successfully used the C# example to download file?
PS: I have installed required nuget pacakages
PM> install-package Google.Apis.Auth
Attempting to resolve dependency 'Google.Apis.Core (≥ 1.9.0)'.
Attempting to resolve dependency 'Microsoft.Bcl (≥ 1.1.9)'.
Attempting to resolve dependency 'Microsoft.Bcl.Build (≥ 1.0.14)'.
Attempting to resolve dependency 'Microsoft.Bcl.Async (≥ 1.0.168)'.
Attempting to resolve dependency 'Microsoft.Net.Http (≥ 2.2.22)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Google.Apis.Auth 1.9.0' already installed.
GoogleDrive already has a reference to 'Google.Apis.Auth 1.9.0'.

IAuthenticator authenticator Used For SDK.There is not much detail on IAuthenticator in google Api But You can Use for API
fileID="asd383d8ied2edj82dnc0v";
Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Execute();
return service.HttpClient.GetStreamAsync(file.DownloadUrl).Result;

Related

Microsoft.VisualStudio.TestTools.UnitTestin - Migrating .net 4.7.2 to .net core

I am in the process of migrating an C# automation solution from .NET4.7.2 to .netCore. I am getting this error and I am not sure how to resolve it.
Issue :
if(!scenarioContext.ScenarioContainer.Resolve<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>().TestName.Contains("text")) { //code }
Error is given on the Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>().TestName
Error : Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'TestTools' does not exist in the namespace 'Microsoft.VisualStudio' (are you missing an assembly reference?).
Managed to resolve it by adding MSTest Nuget packet

Azure Builds - The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft'

Given:
New to Azure Builds
I have a simple WebApi project that uses Swashbuckle.AspNetCore. Everything works fine locally (of course) but when I try to build in Azure builds I get the following error:
The type or namespace name 'OpenApi' does not exist in the namespace
'Microsoft'
I added the SwashBuckle and OpenApi NuGet packages to Azure Artifacts and referenced that in my build script.
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: '/12b2f6b8-fb61-4aac-a526-27a85a46a5b4'
/reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.Xml.XPath.XDocument.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\WindowsBase.dll" /debug+ /debug:portable /filealign:512 /optimize+ /out:obj\Release\netcoreapp3.1\ApiApplication1.dll /target:exe /warnaserror- /utf8output /deterministic+ /analyzer:"C:\Program Files\dotnet\sdk\3.1.202\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Analyzers.dll" /analyzer:"C:\Program Files\dotnet\sdk\3.1.202\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll" /analyzer:"C:\Program Files\dotnet\sdk\3.1.202\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Components.Analyzers.dll" Controllers\WeatherForecastController.cs Program.cs Startup.cs WeatherForecast.cs "C:\Users\rodneysantiago\AppData\Local\Temp.NETCoreApp,Version=v3.1.AssemblyAttributes.cs" obj\Release\netcoreapp3.1\ApiApplication1.AssemblyInfo.cs /warnaserror+:NU1605
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn
[error]RsWpfAndApiSolution\ApiApplication1\Startup.cs(12,17): Error CS0234: The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
Startup.cs(12,17): error CS0234: The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\agent2_work\2\s\RsWpfAndApiSolution\ApiApplication1\ApiApplication1.csproj]
Done Building Project "C:\agent2_work\2\s\RsWpfAndApiSolution\ApiApplication1\ApiApplication1.csproj" (default targets) -- FAILED.
Done Building Project "C:\agent2_work\2\s\RsWpfAndApiSolution\RsWpfAndApiSolution.sln" (default targets) -- FAILED.
Build FAILED.
Uninstall Swashbuckle.AspNetCore and reinstall with the latest version of the same package to resolve this error. Unfortunately VS doesn't show this error but its caught in CI/CD or when you run in Command Line.

The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft'?

I am using ->
Visual Studio 2017 Enterprise Edition,
,.Net Framework 4.5.2
,Microsoft.ServiceBus.dll version 3.0.0.0
In my local system not getting any issues but after pushing changes into release pipeline getting error like below.
Error CS0234: The type or namespace name 'ServiceBus' does not exist
in the namespace 'Microsoft' (are you missing an assembly reference?
Did I missed anything
Add "Microsoft.Azure.ServiceBus" package to your project:
NuGet: Microsoft.Azure.ServiceBus 3.0.0
Configure your Azure DevOps Pipeline with a NuGet Restore:
Azure DevOps: NuGet task

Consume the OData service in C# doesn't work

I tried to understand this tutorial: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
I can generate the proxy without any problems. Just as it is described.
But at chapter "Consume the OData service" it doesn't work. I have named the application and the proxy exactly as shown in the tutorial. How can I make odata available in namespace Microsoft?
Screenshot
Error CS0234 The type or namespace name 'OData' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 6 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
I used:
Microsoft Visual Studio 2017 (Trial)
Microsoft.Data.Edm v5.8.3
Microsoft.Data.Odata v5.8.3
Microsoft.Data.Services.Client v5.8.3
System.Spatial v.5.8.3
WCF Data Services 5.6 Tools (are installed)
continuation:
#Evandro Paula:Thank you for your help! I have come a little further thanks to your help. But unfortunately I have not come to the goal yet.
I installed/updated:
Microsoft Visual Studio 2017 (15.7.1) (Trial)
Microsoft.Data.Edm v5.8.3 (I have not found a more recent one)
Microsoft.Data.Odata v5.8.3 (I have not found a more recent one)
Microsoft.Data.Services.Client v5.8.3 (I have not found a more recent one)
Microsoft.OData.Client v7.4.4 (installed)
Microsoft.OData.Core v7.4.4 (installed)
Microsoft.OData.Edm v7.4.4 (installed)
Microsoft.Spatial v7.4.4 (installed)
System.Spatial v.5.8.3 (I have not found a more recent one)
WCF Data Services 5.6 Tools (are installed)
Screenshot of NuGet
Now the results look like this:
Compiling works with Proxy (TrippinProxy.cs), but without Odata example. (Screenshot)
As soon as I copy the code from the tutorial, compiling does't work anymore. (Screenshot)
using System;
using Microsoft.OData.SampleService.Models.TripPin;
namespace TrippinApp
{
class Program
{
static void Main(string[] args)
{
DefaultContainer dsc = new DefaultContainer(
new Uri("http://services.odata.org/V4/(S(fgov00tcpdbmkztpexfg24id))/TrippinServiceRW/"));
var me = dsc.Me.GetValue();
Console.WriteLine(me.UserName);
}
}
}
source: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
Now the Namespace Microsoft.OData is found. But not Microsoft.OData.SampleService (Screenshot)
I need a little example. How can I initialize the proxy and add a product (CreateProduct)? Or how can I get the example from the tutorial up and running?
First, update the packages you mentioned on your question to their latest version. It looks like Visual Studio didn't use the latest version in your case. I'm using Visual Studio 2017 Enterprise Edition (version 15.7.3) for this test.
Microsoft.OData.Client (version 7.4.4)
Microsoft.OData.Core (version 7.4.4)
Microsoft.OData.Edm (version 7.4.4)
Microsoft.Spatial (version 7.4.4)
Once the packages are up to date, you will observe the following build error, which is related to issue https://github.com/OData/lab/issues/80:
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'EdmxReader' does not exist in the namespace 'Microsoft.OData.Edm.Csdl' (are you missing an assembly reference?) ODataClient C:\temp\NET\ODataClient\Connected Services\TrippingService\TrippingProxy.cs 510 Active
The resolution for this issue is available at https://github.com/juliopinto15/lab/commit/deb1254301a775eb6771b0bed672dd3f56f37cfe.
Just change the proxy (e.g. TrippingProxy.cs) generated code line below as part of method LoadModelFromString():
return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader);
to
return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader);
In my case, I deleted the NuGet cache folder, and it compiles now.
%LOCALAPPDATA%\Nuget\v3-cache
I worked with the same example (TripPinService) and got the same error. It looks like there is an error in the sample.
Instead of:
var context = new DefaultContainer(new Uri(serviceRoot));
You need to write:
var context = new Default.Container(new Uri(serviceRoot));
After that code runs without errors

Azure deployment failes due to missing assembly reference

So I have a simple C# Web API project that I'm attempting to get deployed into Azure. The project builds and runs fine locally (dont they always?!?) but in Azure it fails due to a missing Microsoft.ServiceBus assembly which is used.
The project structure is quite simple:
\
--\Common
----MyProj.common.dll << This uses Microsoft.ServiceBus and has its own packages.config with WindowsAzure.ServiceBus referenced
--\Web
----MyProj.Api << This has an assembly reference to MyProj.common.dll. It doesn't have a reference to WindowsAzure.ServiceBus itself (although I added one to see if it helped, but it didn't)
The output from the Azure deployment script is as follows:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
Restoring packages for D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj...
Installing WindowsAzure.ServiceBus 4.0.0.
Writing lock file to disk. Path: D:\home\site\repository\MyProj\Web\MyProj.Api\obj\project.assets.json
Restore completed in 12.73 sec for D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj.
NuGet Config files used:
D:\local\AppData\NuGet\NuGet.Config
Feeds used:
https://api.nuget.org/v3/index.json
Installed:
1 package(s) to D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
D:\Program Files (x86)\dotnet\sdk\1.0.1\Microsoft.Common.CurrentVersion.targets(1964,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj]
Azure\AQM.cs(7,17): error CS0234: The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj]
Azure\AQM.cs(8,17): error CS0234: The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj]
Azure\AQM.cs(14,17): error CS0246: The type or namespace name 'NamespaceManager' could not be found (are you missing a using directive or an assembly reference?) [D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj]
D:\Program Files (x86)\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for 'D:\home\site\repository\MyProj\MyProj.Shared\MyProj.Common.csproj'. This can indicate a missing project reference. [D:\home\site\repository\MyProj\Web\MyProj.Api\MyProj.Api.csproj]
Failed exitCode=1, command=dotnet publish "MyProj\Web\MyProj.Api\MyProj.Api.csproj" --output "D:\local\Temp\8d493823074840c" --configuration Release
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\62.60430.2807\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
I notice at no point does it attempt to restore the package for the Common assembly - how do I 'tell' Azure to do this? And is this even the issue?
Edit 1
Looking at the deployment script using Kudu, it seems to be doing a solution wide restore, so not sure how/why there is a missing assembly reference:
:: 1. Restore nuget packages
call :ExecuteCmd dotnet restore "MyProj\MyProj.sln"
IF !ERRORLEVEL! NEQ 0 goto error
Thanks
I notice at no point does it attempt to restore the package for the Common assembly - how do I 'tell' Azure to do this? And is this even the issue?
According to your description, your project is .net core project.
You mentioned Servicebus Libriary (WindowsAzure.ServiceBus 4.0.0) is not .NET Core compatible. And the new Libriary, that is a pre-release version, is 100% compatible. We can get more detail here.
We also can find it from another SO thread.
Edit:
According to your comment I update the answer:
I also try to create C# Web API project and deploy to Azure it works correctly on my side.
Please have a try to clean the build and rebuild the project again with a new WebApp.
The following is my detail steps:
1.Create a class libiary project named common and a public ServiceBusHelper class with function GetQueue
2.Create a WebApp project and reference Common.dll and Microsoft.ServiceBus.dll, then change the getvaules function to get queues
public List<QueueDescription> Get()
{
var queueList = Common.ServiceBusHelper.GetQueueList();
return queueList;
}
3.Remove the existed file from the Auzre WebApp during publish the WebApi to Azure
4.Test the WebApp

Categories

Resources