none
Re: Azure, ASP.NET MVC and MEF

    Question

  • Hi,

    I am building an extensible application using asp.net mvc, mef and azure. My issue is how do I copy the external assembly to the asp.net mvc application bin folder using mef. When I try to do this I am getting the
    System.UnauthorizedAccessException error.

    The reason I want to copy external assembly to the bin folder is: I want the latest version of the external assembly always available to the asp.net application. For this to occur I need to copy the latest version of the assembly and overwrite the 'old' assembly in the bin folder. In the bin folder, since it is shadow copied, the assemblies are not locked and so I can overwite the old assembly.

    In summary, I want my external assembly to be used by the main application but should not be locked by the web server process (w3wp.exe) so that I can update the external assembly whenever I want.

     

    Tuesday, September 20, 2011 9:27 PM

Answers

  • To upgrade the role, you need to redeploy the solution. You can either perform a complete redeployment from Visual Studio, or use the portal to upgrade a single role without affecting other roles. It is recommended to use the portal. As long as you have more than 1 instances, upgrading should not cause any downtime.

    Even in local IIS, if you want to modify the bin folder, the web application must be restarted. So it is recommended not to modify bin at runtime.


    Sining Oh Blue Star
    Friday, September 23, 2011 2:50 AM
  • I have solved the problem as follows:

    1. From the main web application, I pulled out the functionality that was using MEF into a separate assembly (dll). Lets call it DoWork.dll.

    2. Do the MEF magic etc., in this assembly (DoWork.dll). i.e. load the types into DoWork.dll from an external assembly (lets call it Analytics.dll) using MEF.

    3. In the main application we load this assembly (DoWork.dll) in a new appdomain using “CreateInstanceFromAndUnwrap” method to create a proxy, do the work and unload the new app domain.

    4. All the required classes inherit from MarshalByRefObject class.

    5. Because the new app domain is unloaded the external assembly (Analytics.dll) is not locked anymore, so can be updated (e.g. overwritten with an updated dll) without stopping the web application.

    Appreciate any thoughts on above solution.

     

    Tuesday, September 27, 2011 12:38 AM

All replies

  • I don't think you have write access to the bin folder. But you can download the assemblies to local storage, and then dynamically load the assemblies from local storage into the current app domain. MEF's AssemblyCatalog doesn't care where the assembly is stored. You simply need to provide a loaded assembly in the constructor.

    If you have to modify the bin folder, the only solution is to upgrade the role.


    Sining Oh Blue Star
    Thursday, September 22, 2011 5:24 AM
  • The problem is once the assembly is loaded from the local storage, it is also locked and so cannot be updated.

    That is why I want to copy it to the bin folder and then load it from there. In the bin folder files are shadow copied so can be updated any time.

    Can you please give more details with regards to upgrade the role.

    Thursday, September 22, 2011 1:26 PM
  • To upgrade the role, you need to redeploy the solution. You can either perform a complete redeployment from Visual Studio, or use the portal to upgrade a single role without affecting other roles. It is recommended to use the portal. As long as you have more than 1 instances, upgrading should not cause any downtime.

    Even in local IIS, if you want to modify the bin folder, the web application must be restarted. So it is recommended not to modify bin at runtime.


    Sining Oh Blue Star
    Friday, September 23, 2011 2:50 AM
  • I have solved the problem as follows:

    1. From the main web application, I pulled out the functionality that was using MEF into a separate assembly (dll). Lets call it DoWork.dll.

    2. Do the MEF magic etc., in this assembly (DoWork.dll). i.e. load the types into DoWork.dll from an external assembly (lets call it Analytics.dll) using MEF.

    3. In the main application we load this assembly (DoWork.dll) in a new appdomain using “CreateInstanceFromAndUnwrap” method to create a proxy, do the work and unload the new app domain.

    4. All the required classes inherit from MarshalByRefObject class.

    5. Because the new app domain is unloaded the external assembly (Analytics.dll) is not locked anymore, so can be updated (e.g. overwritten with an updated dll) without stopping the web application.

    Appreciate any thoughts on above solution.

     

    Tuesday, September 27, 2011 12:38 AM
  • Hi,

    You can club all the referenced dll in single dll using a ILMerge which you can download using following link-

    https://www.microsoft.com/en-us/download/details.aspx?id=17630

    This tool will club all dll and then You can use that single dll as MEF Plugin.


    Thursday, April 11, 2019 6:13 AM