Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Azure MVC 3 web role not starting after adding TwilioController base class inheritance

Azure web role (MVC 3 project) wont' start with Twilio controller class

  • I have an MVC 3 app that is hosted on MS Azure. It publishes to Azure Web role - No problems.
  • I added the Nuget Twilio and Twilio.Mvc packages. It still published to Azure Web role - No problems.
  • I added a class that inherits from the Mvc.TwilioController base class and subsequently the Azure web role no longer starts.
  • If I remove the TwilioController class inheritance the web role starts.

The projects publishes, runs and twilio functions fine in my local VS Azure emulator environment.

The project References; Twilio.api, Twilio.mvc, Twilio.Twiml, RestSharp, and NewtonSoft.Json are all set to CopyLocal=True.

All Azure Diagnostic logging/tracing is enabled and sending to table storage every 5 seconds but no log data is available when the web role fails to start. Note: If I comment out the twilioController I get an abundance of log data so Azure Diags are configured correctly.

Because the web role continues to abort/cycle/abort, there is no opportunity to RDP to the vm for further troubleshooting.


The following two errors are written to the failing web role's Windows System Event Log about every minute:

The application '/' belonging to site '1273337584' has an invalid AppPoolId 'ca5c9ecb-e68d-4f3a-84c2-c0b4430373e9' set. Therefore, the application will be ignored.

.

Site 1273337584 was disabled because the root application defined for the site is invalid. See the previous event log message for information about why the root application is invalid.


Steps to reproduce (exact steps):

  1. Install Azure Sdk v 1.6
  2. Create a new project using the Azure template (visual studio 10 sp1)
  3. Choose the Asp.net MVC 3 Web Role
  4. Build and Publish to Azure
  5. Success - Web Role starts
  6. Add Nuget Package "Twilio" version 3.3.2
  7. Add Nuget Package "Twilio.Mvc" version 3.1.3
  8. Build and Publish To Azure
  9. Success - Web Role starts
  10. Create an empty controller (HelloController). See below code snippet.
  11. Add TwilioController base class (e.g. Public Class HelloController : TwilioController)
  12. Build and Publish to Azure
  13. Fail - the web role just cyles/aborts/cyles.
  14. Comment out TwilioController (e.g. Public Class HelloController // :TwilioController)
  15. Buld and Publish to Azure
  16. Success - web role starts

    using System.Web.Mvc;
    using Twilio.TwiML.Mvc;
      namespace WindowsAzureProject857481.Controllers
        {
            public class HelloController : TwilioController
            {
                //
                // GET: /Hello/
    
                public ActionResult Index()
                {
                    return View();
                }
    

Any ideas appreciated.

Thanks, Jim

like image 847
JimSTAT Avatar asked Dec 14 '11 21:12

JimSTAT


2 Answers

Jim:

I work for Twilio, and own the .NET helper library.

Whats happening is that the Twilio.Mvc assembly is looking for 2.0 version the System.Web.Mvc assembly, since that's what its built against. Its not finding it because its obviously not being packaged with your MVC 3 project.

The fix if fairly easy. Get the Twilio.Mvc source, change the reference to the newer version of MVC and recompile the assembly. I believe our support team is going to contact you with a version I built for you if you don't want to do it yourself.

I think there is probably also a way to use assembly binding redirects to fix the problem as well, if you wanted to try that.

Devin

like image 157
Devin Rader Avatar answered Nov 15 '22 02:11

Devin Rader


I went through your repro steps, except that I changed one thing -- I enabled WebDeploy for the role early, before adding the twilio+deps packs and extending a controller from TwilioController. This way, the VM was already created and the role already started.

  1. Publish new MVC3 role to Azure, enabling web deploy - works
  2. Add Twilio NuGet packs and web deploy - still works
  3. Extend from TwilioController and web deploy -

The first time I did step 3, web deploy caused an error:

COM object has been separated from its underlying RCW cannot be used

I am now retrying to make sure this last step is reproducible with WebDeploy. Have removed all Twilio and am publishing again to reset webdeploy. Will update answer in about 30 minutes.

Update

Ok, this is strange. I was able to reproduce the error above. However, I closed Visual Studio, restarted, and was then able to web deploy. I now have a controller in an MVC3 web role on Azure that extends TwilioController. <-- note this is temporary and will be removed.

I suggest you try the steps above, and even try your repro without using WebDeploy. However, before deploying with a controller that extends TwilioController, close and restart Visual Studio.

If that still doesn't work, try this:

  1. Right-click Azure project and choose Package.
  2. Go to portal, and click New Staging Deployment.
  3. Navigate to and upload the cscfg and cspkg files manually.

Final Answer

I tried the steps above. When disabling web deploy, it appears to not matter whether the package is published from Visual Studio or manually from the portal. Both keep aborting and retrying. The only way I could get the TwilioController to deploy was by using WebDeploy, but of course this is not acceptable.

I suggest you file a support request with Microsoft. It doesn't appear to be a dependency as you mentioned though, since I was able to run the code on an instance by sneaking in the Twilio stuff over web deploy. It could have something to do with the COM object error mentioned above.

P.S. -- you owe me 96 cents for 8 hours of a small compute instance.

like image 32
danludwig Avatar answered Nov 15 '22 04:11

danludwig