Debugging a Plugin throws "Could not load type 'Microsoft.Xrm.Sdk.IPluginExecutionContext4' from assembly 'Microsoft.Xrm.Sdk" - debugging

I just want to debug a plugin via the PluginRegistrationTool.
I have just updated the plugin with the latest version.
So the deployed plugin and the code are in sync. When I start debugging (Attach VS to PluginRegistrationTool and start execution) I get the following error:
Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.Xrm.Sdk.IPluginExecutionContext4' from assembly 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at PluginProfiler.Plugins.ServiceWrappers.ExecutionContextWrapper.Deserialize(OperationType operation, String serializedValue)
at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)
at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)
at PluginProfiler.Library.ProfilerExecutionEngine.Execute(ProfilerExecutionConfiguration configuration)
at PluginProfiler.Library.ProfilerExecutionUtility.Execute(PluginPermissions permissions, ProfilerExecutionConfiguration configuration)
at PluginProfiler.Library.ProfilerExecutionUtility.Execute(PluginPermissions permissions, OperationConfiguration operation, ProfilerReportingConfiguration reporting, CrmServiceClient administratorProxy, ITracingService tracing, ILogger pluginILoggerService)
at Microsoft.Crm.Tools.DebugPlugin.DebugPluginViewModel.btnExecutionClicked()
I'm confused but does anybody have an idea why it references IPluginExecutionContext4??!
Nowhere in the project IPluginExecutionContext4 is referenced and the project builds without problems.
Any help is highly appreciated!

Related

Exception thrown by Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider,

Context:
I am updating a 3rd party dependency (NEST by elasticSearch). In the latest version some interfaces have been removed which are now causing my .net core 3.1 app to throw an exception when autofac tries to map my controllers.
Solution: update usage of IIndexResponse and IDeleteByQueryResponse
Problem / Question:
I can't find any reference in my project to the interface and can't work out from the stack trace what is throwing the error, it seems to throw when the code tries to resolve the controllers, however even with all my controllers deleted from the project it still throws the error:
An unhandled exception occurred while processing the request.
ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Nest.IIndexResponse' from assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
Could not load type 'Nest.IDeleteByQueryResponse' from assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
Loader Exceptions:
Could not load type 'Nest.IIndexResponse' from assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
Could not load type 'Nest.IDeleteByQueryResponse' from assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.
DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider, Microsoft.AspNetCore.Mvc.Routing.ActionEndpointFactory)' on type 'ControllerActionEndpointDataSource'.
Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()
DependencyResolutionException: An exception was thrown while activating Microsoft.AspNetCore.Routing.Matching.DfaMatcherBuilder -> λ:Microsoft.AspNetCore.Routing.MatcherPolicy[] -> Microsoft.AspNetCore.Mvc.Routing.DynamicControllerEndpointMatcherPolicy -> Microsoft.AspNetCore.Mvc.Routing.DynamicControllerEndpointSelector -> Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource.
Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action<ResolveRequestContext> next)

Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0

We were running Windows Server 2008 R2 and upgraded to 2016 and since then our applications have stopped running. ASP.NET Web Forms is still working and only MVC seems to have stopped running.
They were all thrwoing HTTP 503 error and after repaiting IIS URL Rewrite Module 2, they have started throwing the following error:
Server Error in '/Mail' Application.
Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'Microsoft.EnterpriseManagement.OperationsManager.Apm.DataCollecting.Producers.Mvc.4.0, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +194
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +80
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +70
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +444
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
I managed to solve by doing two things:
Repairing the IIS URL Rewrite Module
Uninstalling Microsoft Monitoring Agent which contains the assembly that MVC application is complaining about.

Could not load file or assembly 'System.Web.Http.WebHost...' or one of its dependencies. The module was expected to contain an assembly manifest

I have an MVC application that my customers deploy locally. It has worked for years.
I have a customer trying to load it in this environment:
SERVER: Windows Small Business Server 2011 Standard
IIS: 7.5
.NET: 3.5.1 & 4.5
They are deploying as a subdomain, but receive this error:
Server Error in '/' Application.
Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
module was expected to contain an assembly manifest.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly
'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
or one of its dependencies. The module was expected to contain an assembly manifest.
Source Error:
An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified using
the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly
'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'System.Web.Http.WebHost,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The module was expected to contain an assembly manifest.]
site.MvcApplication.Application_Start() in f:\Users\{path}\site\Global.asax.cs:912
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The module was expected to contain an assembly manifest.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext
context, HttpApplication app) +12864673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,
HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers,
IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,
HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The module was expected to contain an assembly manifest.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,
HttpContext context) +12722601
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
I have tried
copying the indicated dll from a working directory to no avail.
checking the application pool information
comparing settings between working sites and this one
Many Google searches
Fresh install of the application and IIS
Nothing we try seems to work. Ideas?
I deleted the bin folder, and rebuilt the application. Then I went through and made certain that the needed dlls were copied to local on publish and it works now.

CLR Can't find a type, even though it's in the same assembly

I'm troubleshooting a WCF problem in our application, and turned on WCF tracing with the WCF Service Configuration Editor in VS 2010, which added the following sharedListener to the web.config:
<sharedListeners>
<add initializeData="D:\Logs\CRCCustomerService\Web_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
Now, when I take steps to reproduce my error, I'm getting an exception thrown from the System.Diagostics library saying that it can't find XmlWriterTraceListener:
Stack Trace:
System.TypeInitializationException: The type initializer for 'System.ServiceModel.DiagnosticUtility' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Couldn't find type for class System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData)
at System.Diagnostics.TypedElement.BaseGetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElement.GetRuntimeObject()
at System.Diagnostics.ListenerElementsCollection.GetRuntimeObject()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Listeners()
And it goes on for several more lines, but this establishes the context.
My question is, since, according to ObjectBrowser and Reflector, XmlWriterTraceListener is a member class of the same assembly that System.Diagnostics is, how can it NOT not be able to find it?
And secondly, since every single line in the exception stack comes from system code, how on earth do I begin to debug the root cause here?
Are you using .NET 4.0?
If not, you have to beware the service config utility. It will hard code the version of the listener to 4.0 and you'll need to manually change your web.config

System.ComponentModel.DataAnnotations MethodAccessException in Automated Controller Unit Test, MVC

First of all I'd like to say that I wouldn't doubt if this is a configuration error, because it's only happening on our CI build server and not on anyone's local development machine. So if anyone has a seemingly obvious configuration suggestion please feel free to point it out, my team doesn't configure the build server so there could be something simply not set up correctly.
I'm running into an issue with one of my automated tests, I'm having this issue in any test that involves the (System.ComponentModel.)DataAnnotations on the Entity that is being used. It seems to only occur with any test that involves the Controller calling TryUpdateModel.
Before I provide the entire error message, here’s a list of some of the things we’ve already tried:
Adding the main MVC assemblies to the “fullTrustAssemblies” section of the app.config of the Test project
Adding the System.ComponentModel.DataAnnotations assembly to the “partialTrustVisibleAssemblies” section of the app.config of the Test project
Adding the System.ComponentModel.DataAnnotations assembly to the AppDomainSetup PartialTrustVisibleAssemblies in code
Trying to use ReflectionPermission.Demand to see if there was a problem with permissions
Ensuring that .NET Framework 4 and MVC3 were installed on the machine
Checking for the registry key(s) talked about in this article
Here's the full error:
Test method qTrade.UnitTests.Web.Controllers.Maintenance.TypeLookupControllerTest.CreatePostSaveInvalidEntityAndModelState threw exception:
System.MethodAccessException: Attempt by security transparent method 'System.Web.Mvc.TypeDescriptorHelper.Get(System.Type)' to access security critical method 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider..ctor(System.Type)' failed.
Assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain
Test method qTrade.UnitTests.Web.Controllers.Maintenance.TypeLookupControllerTest.CreatePostSaveInvalidEntityAndModelState threw exception:
System.MethodAccessException: Attempt by security transparent method 'System.Web.Mvc.TypeDescriptorHelper.Get(System.Type)' to access security critical method 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider..ctor(System.Type)' failed.
Assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.<br> at System.Web.Mvc.TypeDescriptorHelper.Get(Type type)
at System.Web.Mvc.ModelBinders.GetBinderFromAttributes(Type type, Func`1 errorMessageAccessor)
at System.Web.Mvc.ModelBinderDictionary.GetBinder(Type modelType, IModelBinder fallbackBinder)
at System.Web.Mvc.ModelBinderDictionary.GetBinder(Type modelType, Boolean fallbackToDefault)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
at qTrade.UI.Web.Controllers.Maintenance.TypeLookupController.Create(FormCollection collection) in d:\cibuild\qTrade\qTradeCI\Sources\source\UI\qTrade.UI.Web\Controllers\Maintenance\TypeLookupController.cs:line 55
at qTrade.UnitTests.Web.Controllers.Maintenance.TypeLookupControllerTest.CreatePostSaveInvalidEntityAndModelState() in d:\cibuild\qTrade\qTradeCI\Sources\source\Tests\qTrade.UnitTests\Web\Controllers\Maintenance\TypeLookupControllerTest.cs:line 178
at System.Web.Mvc.TypeDescriptorHelper.Get(Type type)
at System.Web.Mvc.ModelBinders.GetBinderFromAttributes(Type type, Func`1 errorMessageAccessor)
at System.Web.Mvc.ModelBinderDictionary.GetBinder(Type modelType, IModelBinder fallbackBinder)
at System.Web.Mvc.ModelBinderDictionary.GetBinder(Type modelType, Boolean fallbackToDefault)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
at qTrade.UI.Web.Controllers.Maintenance.TypeLookupController.Create(FormCollection collection) in d:\cibuild\qTrade\qTradeCI\Sources\source\UI\qTrade.UI.Web\Controllers\Maintenance\TypeLookupController.cs:line 55
at qTrade.UnitTests.Web.Controllers.Maintenance.TypeLookupControllerTest.CreatePostSaveInvalidEntityAndModelState() in d:\cibuild\qTrade\qTradeCI\Sources\source\Tests\qTrade.UnitTests\Web\Controllers\Maintenance\TypeLookupControllerTest.cs:line 178
Any suggestions would be greatly appreciated, thanks!
I Fixed the problem !
This is a combination of running in Medium Trust, having MVC installed in the GAC and using "dynamic" (or a shape) as a ViewModel. Only (and only if) these 3 conditions are true you run into this error. The solution is to change your controller code: instead of returning "View(model)", return "View((object)model)".

Resources