public static string GetAndCheckProjectId(string projectId, MonitoredResource monitoredResource = null)
Determines the correct project id from a string project id and a MonitoredResource.
If the specified project id is not null, it is returned. Otherwise, if the project id of
the MonitoredResource is not null, it is returned. It both are null,
an InvalidOperationException is thrown.
public static string GetAndCheckServiceName(string serviceName, MonitoredResource monitoredResource = null)
Determines the correct service name from a string serviceName and a MonitoredResource.
If the specified service name is not null, it is returned. Otherwise, if the service name of
the MonitoredResource is not null, it is returned. It both are null,
an InvalidOperationException is thrown.
public static string GetAndCheckServiceVersion(string serviceVersion, MonitoredResource monitoredResource = null)
Determines the correct service version from a string serviceVersion and a MonitoredResource.
If the specified service version is not null, it is returned. Otherwise, if the service version of
the MonitoredResource provided or detected is not null, it is returned. It both are null,
an InvalidOperationException is thrown.
public static string GetProjectId(string projectId, MonitoredResource monitoredResource = null)
Determines the correct project ID from a string projectId and a MonitoredResource.
If the specified project ID is not null, it is returned. Otherwise, if the project ID of
the MonitoredResource is not null, it is returned. It both are null, null is returned.
public static string GetServiceName(string serviceName, MonitoredResource monitoredResource = null)
Determines the correct service name from a string serviceName and a MonitoredResource.
If the specified service name is not null, it is returned. Otherwise, if the service name of
the MonitoredResource is not null, it is returned. It both are null, null is returned.
public static string GetServiceVersion(string serviceVersion, MonitoredResource monitoredResource = null)
Determines the correct service version from a string serviceVersion and a MonitoredResource.
If the specified service version is not null, it is returned. Otherwise, if the service version of
the MonitoredResource provided or detected is not null, it is returned. It both are null, null is resturned.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eProject\u003c/code\u003e class in the \u003ccode\u003eGoogle.Cloud.Diagnostics.Common\u003c/code\u003e namespace provides methods for working with Google Cloud project information.\u003c/p\u003e\n"],["\u003cp\u003eThe class offers methods such as \u003ccode\u003eGetAndCheckProjectId\u003c/code\u003e, \u003ccode\u003eGetAndCheckServiceName\u003c/code\u003e, and \u003ccode\u003eGetAndCheckServiceVersion\u003c/code\u003e to determine and validate project IDs, service names, and service versions, respectively, potentially using a \u003ccode\u003eMonitoredResource\u003c/code\u003e for auto-detection.\u003c/p\u003e\n"],["\u003cp\u003eIf both the explicitly provided information (like \u003ccode\u003eprojectId\u003c/code\u003e, \u003ccode\u003eserviceName\u003c/code\u003e, or \u003ccode\u003eserviceVersion\u003c/code\u003e) and the \u003ccode\u003eMonitoredResource\u003c/code\u003e are null, the \u003ccode\u003eGetAndCheck\u003c/code\u003e methods will throw an \u003ccode\u003eInvalidOperationException\u003c/code\u003e, while the \u003ccode\u003eGet\u003c/code\u003e methods will simply return null.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGetProjectId\u003c/code\u003e, \u003ccode\u003eGetServiceName\u003c/code\u003e, and \u003ccode\u003eGetServiceVersion\u003c/code\u003e methods will return null when no information is provided, in contrast to the GetAndCheck methods which throw exceptions.\u003c/p\u003e\n"],["\u003cp\u003eThe document lists multiple previous versions of the library, with 5.2.0 as the latest available.\u003c/p\u003e\n"]]],[],null,["# Google.Cloud.Diagnostics.Common - Class Project (5.3.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.3.0 (latest)](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.Project)\n- [5.2.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.Project)\n- [5.1.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.Project)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.Project)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.Project)\n- [4.3.1](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.Project) \n\n public static class Project\n\nReference documentation and code samples for the Google.Cloud.Diagnostics.Common class Project.\n\nOperations for Cloud Console Projects. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e Project \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Diagnostics.Common](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common)\n\nAssembly\n--------\n\nGoogle.Cloud.Diagnostics.Common.dll\n\nMethods\n-------\n\n### GetAndCheckProjectId(string, MonitoredResource)\n\n public static string GetAndCheckProjectId(string projectId, MonitoredResource monitoredResource = null)\n\nDetermines the correct project id from a string project id and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified project id is not null, it is returned. Otherwise, if the project id of\nthe MonitoredResource is not null, it is returned. It both are null,\nan [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) is thrown.\n\n### GetAndCheckServiceName(string, MonitoredResource)\n\n public static string GetAndCheckServiceName(string serviceName, MonitoredResource monitoredResource = null)\n\nDetermines the correct service name from a string `serviceName` and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified service name is not null, it is returned. Otherwise, if the service name of\nthe MonitoredResource is not null, it is returned. It both are null,\nan [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) is thrown.\n\n### GetAndCheckServiceVersion(string, MonitoredResource)\n\n public static string GetAndCheckServiceVersion(string serviceVersion, MonitoredResource monitoredResource = null)\n\nDetermines the correct service version from a string `serviceVersion` and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified service version is not null, it is returned. Otherwise, if the service version of\nthe MonitoredResource provided or detected is not null, it is returned. It both are null,\nan [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) is thrown.\n\n### GetProjectId(string, MonitoredResource)\n\n public static string GetProjectId(string projectId, MonitoredResource monitoredResource = null)\n\nDetermines the correct project ID from a string `projectId` and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified project ID is not null, it is returned. Otherwise, if the project ID of\nthe MonitoredResource is not null, it is returned. It both are null, null is returned.\n\n### GetServiceName(string, MonitoredResource)\n\n public static string GetServiceName(string serviceName, MonitoredResource monitoredResource = null)\n\nDetermines the correct service name from a string `serviceName` and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified service name is not null, it is returned. Otherwise, if the service name of\nthe MonitoredResource is not null, it is returned. It both are null, null is returned.\n\n### GetServiceVersion(string, MonitoredResource)\n\n public static string GetServiceVersion(string serviceVersion, MonitoredResource monitoredResource = null)\n\nDetermines the correct service version from a string `serviceVersion` and a [MonitoredResource](https://cloud.google.com/dotnet/docs/reference/Google.Api.CommonProtos/latest/Google.Api.MonitoredResource.html).\nIf the specified service version is not null, it is returned. Otherwise, if the service version of\nthe MonitoredResource provided or detected is not null, it is returned. It both are null, null is resturned."]]