Conflict of reference Google.api

Asked

Viewed 64 times

3

I have a reference conflict problem in the Google API.

In my API classes I always rename as follows: SiteTeste.APIS.Google.<Servico>, where service is, Gmail, Translate, Drive or whatever.

Google Translate I name:

namespace SiteTeste.APIS.Google.Translate

The new API I’m using that is from GMAIL I name:

namespace SiteTeste.APIS.Google.Gmail

The problem is in the Gmail API where I need to import some namespaces:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;

If I call the following line in my code, the compiler says:

Google.Apis.Gmail.v1.Data.Message message = new Google.Apis.Gmail.v1.Data.Message();

CS0234 The type name or namespace "Apis" does not exist in the "Siteteste.APIS.Google" namespace"

Which means he’s playing the Google.Apis.Gmail.v1.Data.Message from "Siteteste.APIS.Google", I could resolve this by renaming the namespace of my APIS and removing Google, but I believe there is another way to resolve this conflict. If anyone can give me a north to solve this problem...

  • 2

    Try to put global::Google.Apis.Gmail.v1.Data.Message message = new global::Google.Apis.Gmail.v1.Data.Message();

  • @Maniero Both yours and Renan’s solve my problem, thank you !

1 answer

2


You don’t need to rename namespaces, you can use aliases. A alias is a nickname you give to a namespace. Simply state as follows:

using alias = namespacePropriamente dito.

Your code would look like this:

using FabricaDeChocolate = Google.Apis.Gmail.V1.Data;
using MinhasAPIs = SiteTeste.APIS.Google;

... // muito código
    FabricaDeChocolate.Message message = new FabricaDeChocolate.Message();

This should solve any name resolution conflict issues between your API’s and the Fábrica de Chocolate.

If this doesn’t resolve because your code is within the namespace of your API’s, do as Maniero indicated in his comment. Declare the Google namespace thus:

using FabricaDeChocolate = global::Google.Apis.Gmail.v1.Data;
  • 1

    Certinho, I did not know this resource, +1 dot in my knowledge :D. Both yours and @Maniero’s solved my problem. VALEU

Browser other questions tagged

You are not signed in. Login or sign up in order to post.