I need to call some Dynamics 2011 CRM WebServices from a WebApi build on .Net Core 2.1.
To use CRM SDK I need these dependencies :
- Microsoft.Xrm.Sdk.2011 5.0.18
- Microsoft.Crm.Sdk.Proxy.2011 5.0.18
- Microsot.IdentityModel 6.1.7600.16394
When I call my method this exception is raised :
System.TypeLoadException : 'Could not load type 'System.ServiceModel.Description.MetadataConversionError' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1..ctor(Uri serviceUri, Boolean checkForSecondary)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration..ctor(Uri serviceUri)
at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateManagement[TService](Uri serviceUri)
Is there any workaround to avoid this exception ?
This problem also occurs in IIS Express and aspnet_regiis -iru could no be applied.
I think it is more a .Net Core issue with 4.5 assemblies.
Thanks in advance.
Related
Using Visual Studio 2017, I have created an ASP.NET Core Web Application (.NET Framework). Installed the NuGets for the .NET Framework 4.5.2 dependencies, built, and published the application to my Windows Server box where I have the .NET Core 1.1.1 RunTime installed. I run my app and get the following:
PS C:\Performance_App\v.0.0.1> .\EPiServer.Social.Testing.Performance.Application
Hosting environment: Development
Content root path: C:\Performance_App\v.0.0.1
Now listening on: http://*:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 POST http://socialvm2.ep.se:5000/api/comments multipart/form-data; boundary=----WebKitFormBoundarycVrgT9gRbDmTFv78 946
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action EPiServer.Social.Testing.Performance.Application.Controllers.CommentsController.Post (EPiServer.Social.Testing.Performance.Application) in 168.0949ms
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HL3IML91HVGN": An unhandled exception was thrown by the application.
System.TypeLoadException: Could not load type 'EPiServer.Social.Common.Rest.ResponseMessageHandler' from assembly 'EPiServer.Social.Common.Rest, Version=1.2.0.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7'.
at EPiServer.Social.Comments.Rest.HttpCommentRepository..ctor(IHttpClientFactory httpClientFactory, ICommentRequestFactory requestFactory)
at EPiServer.Social.Comments.DefaultCommentServiceFactory.GetRepository()
at EPiServer.Social.Comments.DefaultCommentServiceFactory.Create()
at EPiServer.Social.Testing.Performance.Application.Controllers.CommentsController..ctor()
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerActivator.Create(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
The .NET Framework dependency tree looks good:
Any ideas as to what this particular problem may be?
I am using Simplemembership in my asp.net web api project. When i try to validate the user using the below code, i get the error(Error 1)
if (!Membership.ValidateUser(username, password))
{
throw new ValidationException("Username or pwassword is incorrect.");
}
Error 1:
Attempt by security transparent method
'WebMatrix.WebData.SimpleMembershipProvider.
ValidateUser(System.String, System.String)' to access security
critical method
'System.Web.WebPages.StringExtensions.IsEmpty(System.String)' failed.
Earlier i got a similar error(Error 2) which i resolved by installing these packages:
Install-Package Microsoft.AspNet.WebHelpers
Install-Package Microsoft.AspNet.WebPages.Data
Error 2:
Attempt by security transparent method
'WebMatrix.WebData.PreApplicationStartCode.OnConnectionOpened(
System.Object, WebMatrix.Data.ConnectionEventArgs)' to access security
critical method 'System.Web.WebPages.
HttpContextExtensions.RegisterForDispose(System.Web.HttpContextBase,
System.IDisposable)' failed.
I did clean the solution and tried, still getting the same error,
Do i need to install any more packages or does even the simplemembership work in web api?
The current fix for me was by upgrading to .Net 4.5.3. I figured this out of frustration. This issue doesnt just affect MVC 5 but core Webmatrix projects as well after upgrading to webpages 3.2.3. I think it is a framework issue that will be fixed with the new Microsoft Identity. The current fix for me is below:
Note: Please use the property pages wizard in visual studio to change your target framework to .Net Framework 4.5.3. It will update your web.config
<compilation debug="true" targetFramework="4.5.3">
<assemblies>
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
Step 1: Install-Package Microsoft.AspNet.WebHelpers
Step 2: Install-Package Microsoft.AspNet.WebPages.Data
Step 3: [Optional] Install-Package Owin
Step 4: Change targetFramework to .Net 4.5.3 via Property pages dialog box
I'm attempting to ninject ApiControllers in an Azure worker role. I've previously accomplished ninjection with the same controllers in an asp.net mvc 5 / web api 2 project in the same solution. Another non ninjected test controller in this WorkerRole project work and serve expected results.
While attempting to add the NuGet package Ninject.Web.WebApi.OwinHost (version 3.2.x) it looks like that package is ?erroneously? requiring a Ninject version ≥ 3.0.0.0 && < 3.1.0.0
I've tried
Install-Package Ninject.Web.WebApi.OwinHost -ProjectName WorkerRole1
Install-Package Ninject.Web.WebApi.OwinHost -Pre -ProjectName WorkerRole1
Install-Package Ninject.Web.WebApi.OwinHost -Version 3.2.0 -ProjectName WorkerRole1
Install-Package Ninject.Web.WebApi.OwinHost -Version 3.2.1-unstable-002 -ProjectName WorkerRole1
I was able to successfully add Ninject.Web.WebApi.SelfHost, however I believe I need the owin flavor and SelfHost didn't appear to install NinjectWebCommon.cs or equivalent. I don't know where to wire up ninject to the owin self host in the worker role once I am successful at including the OwinHost. I'm assuming it will be scaffold-ed in.
Result of attempting to install Ninject.Web.WebApi.OwinHost
PM> Install-Package Ninject.Web.WebApi.OwinHost -Pre -ProjectName WorkerRole1
Attempting to resolve dependency 'Ninject.Web.WebApi (≥ 3.2.0-unstable)'.
Attempting to resolve dependency 'Ninject (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'Ninject.Web.Common (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi (≥ 5.0 && < 6.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.WebHost (≥ 5.1.2 && < 5.2.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.1.2 && < 5.2.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.1.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 4.5.11)'.
Attempting to resolve dependency 'Ninject.Web.Common.OwinHost (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'Ninject.Extensions.ContextPreservation (≥ 3.0 && < 4.0)'.
Attempting to resolve dependency 'Ninject (≥ 3.0.0.0 && < 3.1.0.0)'.
Install-Package : Updating 'Ninject 3.2.2.0' to 'Ninject 3.0.1.10' failed. Unable to find versions of 'Ninject.Web.WebApi, Ninject.Web.Common' that are compatible with 'Ninject 3.0.1.10'.
At line:1 char:1
+ Install-Package Ninject.Web.WebApi.OwinHost -Pre -ProjectName WorkerRole1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
PM>
Probably unrelated however in checking versions of installed package in the WorkerRole I note that a number of packages are IIS specific. Are these needed in an Azure WorkerRole Owin self host? And specifically for Microsoft.AspNet.WebApi.SelfHost I see the following notation yet I do have Microsoft.AspNet.WebApi.OwinSelfHost installed.
This is a legacy package for hosting ASP.NET Web API within your own
process (outside of IIS). Please use the
Microsoft.AspNet.WebApi.OwinSelfHost package for new projects.
Installed packages in WorkerRole
PM> Get-Package -ProjectName WorkerRole1
Id Version Description/Release Notes
-- ------- -------------------------
EntityFramework 6.1.0 Entity Framework is Microsoft's recommended data access technology for new applications.
Microsoft.AspNet.Identity.Core 2.0.0 Core interfaces for ASP.NET Identity.
Microsoft.AspNet.Identity.E... 2.0.0 ASP.NET Identity providers that use Entity Framework.
Microsoft.AspNet.WebApi 5.0.0 This package contains everything you need to host ASP.NET Web API on IIS. ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of client...
Microsoft.AspNet.WebApi.Client 5.1.2 This package adds support for formatting and content negotiation to System.Net.Http. It includes support for JSON, XML, and form URL encoded data.
Microsoft.AspNet.WebApi.Core 5.1.2 This package contains the core runtime assemblies for ASP.NET Web API. This package is used by hosts of the ASP.NET Web API runtime. To host a Web API in IIS use the Microsoft.AspNe...
Microsoft.AspNet.WebApi.Owin 5.1.2 This package allows you to host ASP.NET Web API within an OWIN server and provides access to additional OWIN features.
Microsoft.AspNet.WebApi.Owi... 5.1.2 This package allows you to host ASP.NET Web API within your own process using the OWIN HttpListener server. ASP.NET Web API is a framework that makes it easy to build HTTP services ...
Microsoft.AspNet.WebApi.Sel... 5.1.2 This is a legacy package for hosting ASP.NET Web API within your own process (outside of IIS). Please use the Microsoft.AspNet.WebApi.OwinSelfHost package for new projects.
Microsoft.AspNet.WebApi.Web... 5.0.0 This package contains everything you need to host ASP.NET Web API on IIS. ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of client...
Microsoft.Data.Edm 5.6.1 Classes to represent, construct, parse, serialize and validate entity data models. Targets .NET 4.0, Silverlight 4.0, or .NET Portable Lib with support for .NET 4.0, SL 4.0, Win Pho...
Microsoft.Data.OData 5.6.1 Classes to serialize, deserialize and validate OData payloads. Enables construction of OData producers and consumers. Targets .NET 4.0, Silverlight 4.0 or .NET Portable Lib with sup...
Microsoft.Data.Services.Client 5.6.1 LINQ-enabled client API for issuing OData queries and consuming OData payloads. Supports OData v3. Targets .NET 4.0, Silverlight 4.0 or .NET Portable Lib with support for .NET 4.5, ...
Microsoft.Owin 2.1.0 Provides a set of helper types and abstractions for simplifying the creation of OWIN components.
Microsoft.Owin.Diagnostics 2.1.0 Provides middleware components to assist in developing OWIN-based applications.
Microsoft.Owin.Host.HttpLis... 2.1.0 OWIN server built on the .NET Framework's HttpListener class. Currently the default server used for self-hosting.
Microsoft.Owin.Hosting 2.1.0 Provides default infrastructure types for hosting and running OWIN-based applications.
Microsoft.Owin.SelfHost 2.1.0 Includes components needed to host an OWIN-based application in a custom process.
Microsoft.WindowsAzure.Conf... 2.0.3 Windows Azure Configuration Manager provides a unified API to load configuration settings regardless of where the application is hosted - whether on-premises or in a Cloud Service.
Newtonsoft.Json 6.0.2 Json.NET is a popular high-performance JSON framework for .NET
Ninject 3.2.2.0 Stop writing monolithic applications that make you feel like you have to move mountains to make the simplest of changes. Ninject helps you use the technique of dependency injection ...
Ninject.Web.Common 3.2.0.0 Bootstrapper for web projects
Ninject.Web.Common.Selfhost 3.2.0.0 Adds self hosting support to web common.
Ninject.Web.WebApi 3.2.0.0 Extension for Ninject providing integration with ASP.NET MVC WebAPI 2
Ninject.Web.WebApi.Selfhost 3.2.0.0 Extension for Ninject providing integration with ASP.NET MVC WebAPI 2 Selfhost
Owin 1.0 OWIN IAppBuilder startup interface
System.Spatial 5.6.1 Contains classes and methods that facilitate geography and geometry spatial operations. Targets .NET 4.0, Silverlight 4.0 or .NET Portable Lib with support for .NET 4.0, SL 4.0, Win...
WindowsAzure.Storage 3.1.0.1 This client library enables working with the Windows Azure storage services which include the blob service for storing binary and text data, the table service for storing structured...
PM>
I know this is late, but I ran into this same problem and found this question via a Google search. I eventually got around it with -DependencyVersion:
Install-Package Ninject.Web.WebApi.OwinHost -DependencyVersion Highest
If you don't want to update all of the dependent NuGet packages, I found that manually installing all of the Ninject-related dependencies for Ninject.Web.WebApi.OwinHost and then installing Ninject.Web.WebApi.OwinHost also got around the issue.
I was facing the same problem today and I solved it by the following
add the following class implementation to your project
public class NinjectDependencyScope : IDependencyScope
{
IResolutionRoot resolver;
public NinjectDependencyScope(IResolutionRoot resolver)
{
this.resolver = resolver;
}
public object GetService(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has been disposed");
return resolver.TryGet(serviceType);
}
public System.Collections.Generic.IEnumerable<object> GetServices(Type serviceType)
{
if (resolver == null)
throw new ObjectDisposedException("this", "This scope has been disposed");
return resolver.GetAll(serviceType);
}
public void Dispose()
{
IDisposable disposable = resolver as IDisposable;
if (disposable != null)
disposable.Dispose();
resolver = null;
}
}
// This class is the resolver, but it is also the global scope
// so we derive from NinjectScope.
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
IKernel kernel;
public NinjectDependencyResolver(IKernel kernel)
: base(kernel)
{
this.kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(kernel.BeginBlock());
}
}
2- then in NinjectWebCommon
add the following line of code to this method CreateKernel():
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
so the complete implementation will be:
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
// Install our Ninject-based IDependencyResolver into the Web API config
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
I tried this code my self and it works successfully
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
After migrating a solution from MVC 1.0.0.0 Visual Studio 2008 to MVC 2.0.0.0 Visual Studio 2010 I get the following error:
The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
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.ArgumentException: The controller factory type 'MyLib.MyControllerFactory' must implement the IControllerFactory interface.
Parameter name: controllerFactoryType
Source Error:
Line 35: protected void Application_Start()
Line 36: {
... container initialization ...
Line 38: ControllerBuilder.Current.SetControllerFactory(typeof(MyControllerFactory));
MyLib is an external shared library implemented in MVC 1.0.0.0
MyLib is an external shared library implemented in MVC 1.0.0.0
You will have to recompile (if you have the source code) or ask the author of the library to provide you a version compiled against System.Web.Mvc Version 2.0.0.0 or this won't work.
Here's workaround I've found to make work my MVC 1.0.0.0 dependency under my MVC 2.0 website migrated to Visual Studio 2010.
In the Application_start in Global.asax I just instantiated the IControllerFactory using the implementation class MyControllerFactory instead of trying to get its type:
ControllerBuilder.Current.SetControllerFactory((IControllerFactory) new MyControllerFactory());
With that error fixed, then I got another crash:
<b>Entry point was not found. </b>
<b>Description:</b> 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.
<b>Exception Details:</b> System.EntryPointNotFoundException: Entry point was not found.
<b>Source Error: </b>
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.
<b>Stack Trace: </b>
[EntryPointNotFoundException: Entry point was not found.] System.Web.Mvc.IControllerFactory.CreateController(RequestContext requestContext, String controllerName) +0
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +181
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +85
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +392
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263
This was produced because the legacy MVC 1.0 library wasn't able to resolve MVC the reference to the interface in MVC 2.0 library loaded in the application.
I solved this by adding the following section in the config file to add assembly binding from System.Web.Mvc 1.0.0.0 to System.Web.Mvc 2.0.0.0:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<!-- Binding to help Common library MVC 1 code find the classes in MVC 2 -->
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
I also had to add this configuration block to the app.config file in my unit tests project to fix the broken tests.