Wednesday, February 24, 2021

How to fix error “ANCM In-Process Handler Load Failure”?

If you are getting this error:


This issue in .Net core 2.2. so one solution is for it checks the Dotnet-hosting version if you are you are using less than the 2.2.8 upgrade it into 2.2.8 version then the issue will be solved.
Hope it helps you.Thank you 




Wednesday, February 3, 2021

How can I call an async method in Main?

That kind if issue are facing beginner and those developer are not familiar with async and await used.
So in this post i have explain you how to call async method.

 
namespace PracticeHemaware
{
class Program
{
private static string result = "123";

static void Main(string[] args)
{
var data= Task.Run(async () => await saytest());
// saytest(result).Wait();
Console.WriteLine(data.Result);

Console.Read();
}
static async Task<string> saytest()
{
await Task.Delay(5);
result = "Hello World";
return result;
}
}
}
this is my code and saytest() is my async method.

Thank you.

Tuesday, February 2, 2021

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync

 Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync 

Error:
Full error is as below, while generating reports in Developer VM.

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.Exists(Boolean primaryOnly, TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.CreateIfNotExists(TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.DynamicsOnline.Infrastructure.Components.TableAccessor.TableStorageAccessor.PerformOperation(CloudStorageAccount storageAccount, String tableName, Func`1 operation) at

Reason:
Azure emulator service is not running due to port conflict with another windows service.
 
How to find what is running on what port?

using any of the below commands in cmd will give you list of the ports used by services.

netstat -bano

netstat -a

In my case, those ports were in use by windows application, which i can not stop or change port.

How to solve error?

To resolve this error open CMD with Administrative privileges

Navigate to location: "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\"

Execute command AzureStorageEmulator.exe start.

In my case service was not started due to same ports were being used by another application.

I have changed port number for Azure Emulator to run on different port and started service.

Below is Picturization for the same.


 

 

 

 

 

 

 

Thank you .

Upload Image To Azure China Blob Storage In ASP.NET MVC

 Upload Image To Azure China Blob Storage In ASP.NET MVC Code.
 1st step:-Use below code in web.config file.

<appSettings>
    <add key="StorageAccountName" value="YOURAZURECHINAACCOUNTNAME" />
    <add key="StorageAccountKey" value="YOURAZURECHINAACCOUNTKEY" />
  </appSettings>

The below is controller code

I am using service here the code are as below:-

using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace BlobStorageDemo
{
    public class ImageService
    {
        public async Task<string> UploadImageAsync(HttpPostedFileBase imageToUpload)
        {
            string account = CloudConfigurationManager.GetSetting("StorageAccountName");
            string key = CloudConfigurationManager.GetSetting("StorageAccountKey");
            string imageFullPath = null;
            if (imageToUpload == null || imageToUpload.ContentLength==0)
            {
                return null;
            }
            try
            {
                StorageCredentials credn = new StorageCredentials(account, key);
                CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credn, new Uri("https://deice2staging.blob.core.chinacloudapi.cn "),
           new Uri(" https://deice2staging.blob.core.chinacloudapi.cn/ "),
           new Uri("https://deice2staging.blob.core.chinacloudapi.cn/ "), null);
                //CloudStorageAccount cloudStorageAccount = ConnectionString.GetConnectionString();
                CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("blobstor1");

                if(await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(
                        new BlobContainerPermissions {
                            PublicAccess = BlobContainerPublicAccessType.Blob
                        }
                        );
                }
                string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(imageToUpload.FileName);

                CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName);
                cloudBlockBlob.Properties.ContentType = imageToUpload.ContentType;
                await cloudBlockBlob.UploadFromStreamAsync(imageToUpload.InputStream);

               imageFullPath = cloudBlockBlob.Uri.ToString();
            }
            catch (Exception ex)
            {

            }
            return imageFullPath;
        }
    }
}

and my UI code are as below :-


@{
    ViewBag.Title = "Upload";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Upload Image</h2>
<br />

@using (Html.BeginForm("Upload", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset class="form-horizontal">
        <div class="form-group">
            <label class="control-label col-md-2" for="Photo">Photo</label>
            <div class="col-md-10">
                <input type="file" name="photo" />
            </div>
        </div>
        <div class="form-group">
            &nbsp;
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Submit" class="btn" />
            </div>

        </div>
    </fieldset>
   
}


Thank you .

Hope it is help you