locked
System.PlatformNotSupportedException RRS feed

  • Question

  • I have a job that's scheduled every night that connects to the azure batch apps service, lists out the jobs and checks to see if any of them have failed.

    It's been working for the last 3 weeks, but last night it failed with this exception:

    2015/03/20 13:47:03.6030807 - ErrorCollection - System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.Common.ServiceClient`1' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
       at Microsoft.WindowsAzure.Common.Internals.PortablePlatformAbstraction.GetPlatformAssembly(Assembly callingAssembly)
       at Microsoft.WindowsAzure.Common.Internals.PortablePlatformAbstraction.Get[T](Boolean hasDefaultImplementation)
       at Microsoft.WindowsAzure.Common.ServiceClient`1..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.WindowsAzure.Common.ServiceClient`1..ctor()
       at Microsoft.Azure.Batch.Apps.Protocol.BatchAppsManagementClient..ctor()
       at Microsoft.Azure.Batch.Apps.Protocol.BatchAppsManagementClient..ctor(SubscriptionCloudCredentials credentials, Uri serviceUri)
       at Microsoft.Azure.Batch.Apps.BatchAppsClient..ctor(String serviceUri, TokenCloudCredentials tokenCloudCredentials)
       at PCDS.Infrastructure.Services.Azure.Batch.BatchService.GetClient() in c:\TeamCity\buildAgent\work\1f3f7bd8af0fcff0\Source\PCDS.Infrastructure.Services.Azure\Batch\BatchService.cs:line 87
       at PCDS.Infrastructure.Services.Azure.Batch.BatchService.<GetAllJobsAsync>d__5.MoveNext() in c:\TeamCity\buildAgent\work\1f3f7bd8af0fcff0\Source\PCDS.Infrastructure.Services.Azure\Batch\BatchService.cs:line 30
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at PCDS.BatchJobs.Jobs.ErrorCollectionJob.RunTask(JobTask task) in c:\TeamCity\buildAgent\work\1f3f7bd8af0fcff0\Source\PCDS.BatchJobs\Jobs\ErrorCollector\ErrorCollectionJob.cs:line 44
    ---> (Inner Exception #0) System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.Common.ServiceClient`1' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
       at Microsoft.WindowsAzure.Common.Internals.PortablePlatformAbstraction.GetPlatformAssembly(Assembly callingAssembly)
       at Microsoft.WindowsAzure.Common.Internals.PortablePlatformAbstraction.Get[T](Boolean hasDefaultImplementation)
       at Microsoft.WindowsAzure.Common.ServiceClient`1..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.WindowsAzure.Common.ServiceClient`1..ctor()
       at Microsoft.Azure.Batch.Apps.Protocol.BatchAppsManagementClient..ctor()
       at Microsoft.Azure.Batch.Apps.Protocol.BatchAppsManagementClient..ctor(SubscriptionCloudCredentials credentials, Uri serviceUri)
       at Microsoft.Azure.Batch.Apps.BatchAppsClient..ctor(String serviceUri, TokenCloudCredentials tokenCloudCredentials)
       at PCDS.Infrastructure.Services.Azure.Batch.BatchService.GetClient() in c:\TeamCity\buildAgent\work\1f3f7bd8af0fcff0\Source\PCDS.Infrastructure.Services.Azure\Batch\BatchService.cs:line 87
       at PCDS.Infrastructure.Services.Azure.Batch.BatchService.<GetAllJobsAsync>d__5.MoveNext() in c:\TeamCity\buildAgent\work\1f3f7bd8af0fcff0\Source\PCDS.Infrastructure.Services.Azure\Batch\BatchService.cs:line 30<---

    The code that gets the job is nothing fancy:

    public async Task<IEnumerable<BatchJob>> GetAllJobsAsync(TimeSpan timespan)
    {
        DateTime minDate = DateTime.UtcNow - timespan;
        client = GetClient();
        var jobs = await client.Jobs.ListAsync();

        return jobs
            .Where(j => j.SubmissionTime > minDate)
            .Select(j => Mapper.Map<BatchJob>(j))
            .ToList();
    }

    BatchAppsClient client;
    private BatchAppsClient GetClient()
    {
        if (client == null)
        {
            string accountId = ConfigFactory.PcdsConfig.BatchServiceUnattendedAccountId;
            string accountKey = ConfigFactory.PcdsConfig.BatchServiceUnattendedAccountKey;
            string batchAppsServiceEndpoint = ConfigFactory.PcdsConfig.BatchServiceEndpoint;

            var user = AuthenticationUserCredential.Parse(accountId, accountKey);

            // Create AAD token 
            var authToken = TokenCloudCredentialsUtils.GetAuthenticationToken(user);

            // Create Batch Apps Client 
            client = new BatchAppsClient(batchAppsServiceEndpoint, authToken);
        }
        return client;
    }

    I checked to see if there was an updated nuget for the batch apps packages, but didn't find any.

    Friday, March 20, 2015 2:32 PM

Answers

  • This looks like it may be a deployment issue with the Microsoft.WindowsAzure.Common DLL, on which the Batch Apps client DLL depends.  WA.Common loads per-platform implementation DLLs with names like Microsoft.WindowsAzure.Common.NetFramework.dll, Microsoft.WindowsAzure.Common.WindowsPhone.dll, etc.  I suspect that, for some reason, the ...NetFramework DLL has not been xcopied to your bin directory.  (I've seen this happen in other contexts though not with the Batch Apps client library.)

    If this doesn't help, can you let us know:

    * Did the failure start happening after a redeployment, or just out of the blue?

    * Can you provide us with a directory listing of the bin directory please?

    * The assembly versions of WA.Common.dll and WA.Common.NetFramework.dll in the bin directory

    Thanks!

    • Marked as answer by blueawning Monday, March 23, 2015 12:49 AM
    Sunday, March 22, 2015 9:10 PM

All replies

  • This looks like it may be a deployment issue with the Microsoft.WindowsAzure.Common DLL, on which the Batch Apps client DLL depends.  WA.Common loads per-platform implementation DLLs with names like Microsoft.WindowsAzure.Common.NetFramework.dll, Microsoft.WindowsAzure.Common.WindowsPhone.dll, etc.  I suspect that, for some reason, the ...NetFramework DLL has not been xcopied to your bin directory.  (I've seen this happen in other contexts though not with the Batch Apps client library.)

    If this doesn't help, can you let us know:

    * Did the failure start happening after a redeployment, or just out of the blue?

    * Can you provide us with a directory listing of the bin directory please?

    * The assembly versions of WA.Common.dll and WA.Common.NetFramework.dll in the bin directory

    Thanks!

    • Marked as answer by blueawning Monday, March 23, 2015 12:49 AM
    Sunday, March 22, 2015 9:10 PM
  • Yep, that was it.

    The reference to WA.Common and WA.Common.NetFramework were removed from the project so they were missing in the deployment.

    Thanks!

    Monday, March 23, 2015 12:48 AM
  • Hi,

    Is there any specific step to fix this. I searched for WA.Common in nuget got not luck.

    Friday, May 1, 2015 6:59 AM