Missing method in Google.Apis.Urlshortener get_ServiceParameters

377 views Asked by At

I am trying to use Google Shortener URL API https://developers.google.com/url-shortener/v1/getting_started but I am facing a hefty issue when using the C# library Google.Apis.Urlshortener.v1. I am trying to call "insert" on URL in order to get a shortened url using OAUTH2.0 authentication. I have successfully retrieved a valid refresh token and authenticator, but there seems to be something missing when executing the function. I hope there are someone who have made this work.

Code:

var init = new BaseClientService.Initializer();
init.Authenticator = _authenticator; 
//init.ApiKey = ApiKey;
var urlService = new UrlshortenerService(init);
var shortUrl = urlService.Url.Insert(new Url { LongUrl = url }).Execute().Id; // fails...

Stack trace:

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Method 'get_ServiceParameters' in type 'Google.Apis.Urlshortener.v1.UrlshortenerService' from assembly 'Google.Apis.Urlshortener.v1, Version=1.5.0.18, Culture=neutral, PublicKeyToken=null' does not have an implementation.
</ExceptionMessage>
<ExceptionType>System.TypeLoadException</ExceptionType>
<StackTrace>
at DoguApi.Controllers.UrlShortenerController.GetShortenedUrl(String url) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
</StackTrace>
</Error>
1

There are 1 answers

0
Sindre On BEST ANSWER

Short answer: Update all referenced Google.Apis 'DLL-files in all projects in the solution to the same verison.

Long answer: My problem was that I had two projects in my Solution, one that included Google.Apis v.1.4.0 and one that included Google.Apis v.1.5.0. Because the one with Google.Apis v.1.4.0 was serving the other project through a REST API, the error was not found on compile time. By updating both to the newest version the error got resolved.