Azure Web Sites Native C++ DLL (p/invoke)

Sometimes you need improve performance of your code or using library which written on other language. Today we will talk how to create x64 C++ library and how to invoke method in C# Azure Web Site.

  1. Create C++ dll library in VS
  2. In project settings (Linker -> Advanced) set Target Machine to MachineX64 (/MACHINE:X64)
  3. In project setting (C/C++ -> Advanced) set Calling Convention to __cdecl (/Gd)
  4. For example create header and source files with name ExpressionExecuter
  5. In header file define prototype function:
  6. Source file realize method ValidateExpression:
  7. Configure Azure Web Site using method described here
  8. Now we need to realize invoke method in C# project:
  9. Now you can use C++ code using p/invoke in Azure Web Site project:
  10. Don’t forget set X64 configuration settings on staging or production azure web site (Configure Tab -> General -> Platform) select 64-BIT option.

 

Now you have performance code in your C# Azure Web Site project 😉

How I spent half a day trying to solve SSL connection error (ERR_SSL_PROTOCOL_ERROR)

Hope it helps someone to prevent spending a lot of time trying to solve SSL connection error problem during local site debugging.

My web.config contains rewrite section for https requests:

I tried (but it didn’t work):

  • Check localhost ssl certificate
  • Removing rewrite section
  • Clearing rules section after all existing rules
  • Removing localhost from chrome://net-internals/#hsts
  • Change web site port
  • Repairing IIS Express and Visual Studio

The solution was:

  • Just clear cache of your browser (CTRL + R didn’t help)
  • Delete applicationhosts.config in solution folder (.vs/config)

 

Searching Azure Table Storage entities using query like Substring or Left

Using Azure Tables Storage we know that selecting primary key and row key one of the most important things. In my situation I decide to make a complex Row Key. It looks like some GUID + “_” + Other Data.

The next step is searching some data that contains first part of Row Key – GUID. For example to delete entities.

First part is prepare batch deletion. To achieve this I find great solution here.

The second part is make Expression – to filter entities using Substring or Left method. For that we can use CompareTo method.

For example I need remove users by project:

Success. Now we know how to search entities using method like Substring or Left for Azure Table Storage.

Azure Web Role recycling

On one machine, there was an error that didn’t reproduce on other devices.
Web Role can’t start in debug mode with recycling issue.

capture

First of all I checked EmulatorRuntime.log which located in “C:\Users\<user>\AppData\Local\dftmp\EmulatorRuntimeLogs”.

There was a message:

I spend a lot of time trying to fix this issue. Helpful links from stackoverflow.com:

But no one of this solutions solved my problem.

The problem was: Startup Task in ServiceDefinition.csdef made my role recycle.

Solution: So if you have problem with recycling check your startup tasks.