c# – Google.api Referral Conflict

Question:

I'm having a Google API reference conflict issue.

In my API classes I always rename it like this: 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 is from GMAIL I name it:

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

Error CS0234 Type name or namespace "Apis" does not exist in namespace "SiteTeste.APIS.Google"

Ie he is playing the Google.Apis.Gmail.v1.Data.Message from "SiteTeste.APIS.Google" I could fix this by renaming the namespace of my APIS and remove Google, but I believe there is another way to resolve that conflict. If anyone can give me a direction to solve this problem…

Answer:

You don't need to rename namespaces, you can use aliases . An alias is a nickname you give to a namespace . Just declare it 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 between your API's and the Chocolate Factory API's.

If that doesn't work because your code is inside your API's namespace, do as Maniero indicated in his comment. Declare the Google namespace like this:

using FabricaDeChocolate = global::Google.Apis.Gmail.v1.Data;
Scroll to Top