MEF: Assemblies getting removed from catalog? - iis

I've added MEF to my web api project using IDependencyExplorer and all works fine.
However, after a few minutes of running, I start to get export not found errors.
When I check the catalog in the debugger, the exports have gone and the assembly that contains the exported type is no longer there.
We aren't removing assemblies from the catalog explicity, so I'm baffled as to why this is happening. Would anyone be able to shed some light on this?

Just figured out what was happening.
I use an aggregate catalog and add the assemblies containing my exports into it.
The first time the web site starts, all required assemblies were loaded in the current app domain, so everything was working fine.
Later on the IIS process was recycling/restarting. When this happens and a new web request is received, not all the assemblies I needed were loaded, and I had put a guard to only add loaded assemblies into the aggregate catalog.
The solution is to force the loading of the assemblies if they have not been loaded yet, or to use a directory catalog instead.
Hope this helps anyone else who experiences this issue.

Related

Orchard 1.8 Can't Enable Custom Module

I am in the process of upgrading from Orchard 1.7 to 1.8. Everything seems fine locally, but when I deploy my site, 1 of my custom modules is disabled. When I click the "Enable" link in the modules section of the dashboard, the page refreshes, but the module is still disabled. My local instance is connected to the same database and shows the module enabled so not really sure what is happening. I don't see any details in the standard error logs.
Is there any way to see any errors that could be causing a module to fail being enabled?
Thanks
This turned out to be due to a case mismatch in my feature name vs my module folder name. My module was originally named in Pascal case ie. 'MyModule'. Somewhere along the way my folder had gotten renamed to 'Mymodule' while the Module.txt file still listed the primary feature as 'MyModule'.
I finally hunted this down by copying the Orchard.Modules.pdb file into the bin folder of my precompiled web application and attached the VS debugger to it to see what was going on. The issue presented itself inside of Orchard.Modules.Controllers.AdminController.Features() where a comparison of FeatureDescriptor.Id == ShellFeature.Name failed to match on account of the case mismatch. The result was that my feature was being shown as disabled even though it is enabled in the database.
Not a direct answer to your question but did you do a complete rebuild before publishing your orchard site (assuming that is how you deployed it)? I have found that sometimes you have to do a rebuild all before publishing.

Rewriting IL using custom .net profiler in Microsoft SharePoint 2013 (IIS Server)

I'm writing a custom .net profiler to rewrite some methods in SharePoint 2013 on the fly.
The Class I'm interested is Microsoft.SharePoint.Utilities.DateOptions.
I've implemented ICorProfilerCallback::JITCompilationStarted and ICorProfilerCallback::JITCachedFunctionSearchStarted in my profiler and am currently just logging all functions being compiled. Also, I've set eventFlags as follows
DWORD eventMask =
COR_PRF_DISABLE_ALL_NGEN_IMAGES |
COR_PRF_DISABLE_INLINING |
COR_PRF_MONITOR_JIT_COMPILATION |
COR_PRF_MONITOR_CACHE_SEARCHES;
The problem is, No matter what I do, no method of DateOptions class will be compiled. I am sure that it should be called, and I've already tested my changes by disassembling, updating code, and reassembling it's DLL. I can see other classes in the same namespace loading and compiling (and can successfully rewrite them) but not this one. The decision to use a profiler for the job is a business decision and can not be reverted.
One point of interest is that this class is used on the code generating the page and its web parts, and I can see no other related classes in this code-path too.
I've enabled my profiler system-wide using system environment variables, and have tried rebooting so it will profile everything from startup to no avail.
Am I missing something here?
Edit: I guess it should be some setting inside IIS or something. I can see all normal classes and namespaces, but nothing that runs while rendering the page in IIS.
I finally solved my problem. It was kind of a dumb mistake I guess, but still I'm putting it here so no one else gets stuck like me!
I was using a specific folder on my C drive for development, and ASP.Net user account did not have read privileges to that folder, and could not load the profiler.
Parts of the process was run using a privileged account so I was able to log and rewrite it's functions, but the web rendering parts were under a limited account.
Copying the dll to System32 folder fixed all my problems.

SiteMapPath empty after upgrade to MVCSiteMap 4

I just attempted to update the site map provider from 3.3.6.0 to 4.0.14. I followed the instruction on the wiki however my SiteMapPath now renders empty. I made no changes to the mvc.sitemap file other than updating the schema to 4.0. When I debug into the SiteMapPathHelperModel I find that the model has no nodes defined. I am using the internal DI container (I would like to get this working before switching over to the application container).
When I check the sitemap.xml file it is well populated which makes me think that the mvc.sitemap is being read.
I'm out of ideas on this one and would be happy to provide any additional information which may be useful. I'm not even sure where I can hook into debug this problem. Literally the only thing I changed between a working 3.3.6.0 and a not working 4.0.14 was what was prescribed on the wiki.
Ok, since your /sitemap.xml endpoint appears to be working, you are correct the sitemap is being populated and loaded correctly.
There are a couple of things I know of that can cause this to happen:
If you are using Dynamic Node Providers, they must be added to a node that is not otherwise part of the sitemap. See my question here - I am trying to figure out why this is the case as well.
Your routes don't match your nodes - please read Routing Basics and/or post your routes and Mvc.sitemap XML.
If you check the above and everything appears to be correct, please make a small demo project showing a sample of your configuration and open an issue on GitHub, as it is highly likely your specific configuration has something to do with the problem.
BTW - You can debug by cloning the current repo on your system or downloading the solution as a zip, enabling NuGet package restore on your solution (right click the solution > Enable NuGet Package restore), add the MvcSiteMapProvider project to your solution, and then in your project remove the reference to MvcSiteMapProvider and add the reference to the newly added MvcSiteMapProvider project from your MVC project. Then you can add breakpoints and step through the code. I suggest making a backup of your solution (or ensure you can roll back another way) before doing this, and reverting back to your current state when done.
I have documented the whole procedure here: http://www.shiningtreasures.com/post/2013/08/21/debugging-an-mvcsitemapprovider-configuration

Unable to deploy ASP.NET MVC 4 app as Azure Web Site

I have an ASP.NET MVC 4 app that I'm trying to deploy as an Azure Web Site. My app works fine in my local environment. When I publish the site to azure though, I receive the following error:
Multiple types were found that match the controller named 'Root'. This can happen if the route that services this request ('') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Views' has found the following matching controllers:
MyApp.HD.Web.Controllers.RootController
MyApp.Web.Controllers.RootController
Why would I get this error on Azure but not locally? I can't figure out how to get around it.
Thank you
I've had this problem before. Let me explain why it happened.
We added a new project to our solution, let's call it NewProject. This project had been set up incorrectly so we recreated it as NewProject2. Once the project was setup and working, we renamed it to NewProject. This is when the problem started. Under certain build configurations we were getting the same error as you. It was complaining about ambiguous controllers with namespaces NewProject and NewProject2. Doing a find-in-files returned no matches for NewProject2. The was thoroughly frustrating. Given that this was only occuring under certain build configurations was a big sign that the problem was with left-over references in the bin folder(s). Doing a clean didn't seem to fix the problem. The ultimate fix was to do a complete code purge. DLLs typically do not get committed to source control. I backed up and deleted all code and got it back from source control. The issue no longer occurs.
It's worth mentioning that this issue was not global. It only occurred on certain developer machines. I figure the ones that were affect were the ones that had gotten latest from source control during the process of create1/create2/rename2/delete1.
Try doing a clean and rebuild in the affected build config.
Try manually removing your bin and obj folders.
Try a complete code purge

How to publish MSHTHML.dll and SHDOCVW.dll to Azure

I have a 3rd party web page screen capture DLL from http://websitesscreenshot.com/ that lets me target a URL and save the page to a image file. I've moved this code into my Azure-based project and when I run it on my local sandboxed dev box and save to the Azure blob, everything is fine. But when I push the bits to my live server on Azure, it's failing.
I think this is because either MSHTML.dll and/or SHDOCVW.dll are missing from my Azure configuration.
How can I get these libraries (plus any dependent binaries) up to Azure?
I found the following advice on an MSFT forum but haven't tried it yet. http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/0344dcff-6fdd-4479-a3b4-3e89750a92f4/
Hello, I haven't tried mshtml in the cloud. But generally speaking, to
use a native dll in a Web Role, you add the dll to the Web Role
project just like adding a picture (choose add existing items). Then
make sure the Build Action is set to Content. This tells Visual Studio
to copy the dll file to the output package.
Also check dependencies carefully. A lot of problems related to native
code are caused by missing dependencies, such as a particular VC++
runtime dll.
Thought I'd ask here first before I burn a day or two on an unproven solution.
EDIT #1:
it turns out that our problem was not related to MSHTML.dll or SHDOCVW.dll missing from the Azure server. They're there.
The issue is that by default new server instance have the IE security hardening feature enabled, and this was preventing our 3rd party dll from executing script. So we needed to turn off the enhanced IE security configuration settings. This is also a non-trivial exercise.
In the meantime, we just created a server-side version of the feature on our site we need to make screen captures from (e.g. we eliminated JSON-based rendering of UI on the client), and we were able to proceed.
I think the solution mentioned in the MSDN forum thread is correct. You should put them as part of your project files, so that the SDK will package and deploy them to the VM on the cloud.
But if they are COM and need to be registed you'd better call the register command via the Startup feature. Please check http://msdn.microsoft.com/en-us/hh351539
HTH

Resources