Ninject Error activating HttpConfiguration - asp.net-web-api2

I have added the NuGet package: Ninject.Web.WebApi.WebHost to my ASP.NET Web API project, however, once I add all of my DI bindings, I get the following error message:
Error activating HttpConfiguration More than one matching bindings are available. Matching bindings:
1) binding from HttpConfiguration to method
2) binding from HttpConfiguration to method
Activation path: 1) Request for HttpConfiguration
Suggestions: 1) Ensure that you have defined a binding for
HttpConfiguration only once.
These are the NuGet packages that are added along with Ninject.Web.WebAPI.WebHost:
Ninject v. 3.2.2
Ninject.Web.Common v. 3.2.3
Ninject.Web.Common.WebHost v. 3.2.3
Ninject.Web.WebApi v. 3.2.4
Ninject.Web.WebApi.WebHost v. 3.2.4
I have no idea how to resolve this since I was able to get this to work on previous projects, but this project does not seem to be working for whatever reason.
I also encounter this error message frequently with all of these versions of the assemblies:
Make sure that the controller has a parameterless public constructor
Sometimes I am able to build the project correctly with older versions of the Ninject assemblies, but I frequently get the error message:
Sequence contains no elements.
The only way I have discovered to resolve this error is to delete the bin directory and re-build, but I don't understand why I constantly have to delete the bin directory to get Ninject to work properly each time.
Please advise as to how to get Ninject to work properly with Web API v.2.2

I found the solution to this over here.
In short, the solution is to get all Ninject packages to the same version. There was a shuffling around of the HttpConfiguration stuff and if you have different versions of different Ninject packages, it can exist in multiple places. Upgrading everything to the same version should resolve this.

Related

Ambiguous Call when using Should().NotBeNull() on As item

When I do the following test
var contentRes = res as OkNegotiatedContentResult<List<MachineHealthTableDTO>>;
contentRes.Should().NotBeNull();
I get the error
The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should<TDataRow>(TDataRow)' and 'DataSetAssertionExtensions.Should<TDataSet>(TDataSet)'
This started happening when I upgraded from fluent assertions 5 to 6.
Any Idea as to how I can go about resolving this issue would be appreciated.
I had a very similar issue with an enum
actualEnumValue.Should().Be(expectedEnumValue);
with the error
Error CS0121 The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'
I finally managed to solve the issue by removing <LangVersion>7</LangVersion> from the project file.
I've just had this exact issue with a .NET Framework 4.8 console app. Would build fine locally but failed the build step in the Azure DevOps pipeline.
Turns out that pipeline was using the vs2017-win2016 vm. Bumping it up to windows-2019 - which used Visual Studio 2019/later version of MSBuild - sorted the issue.
As a quickfix for the failing build I changed the extension method to
AssertionExtensions.Should(contentRes).NotBeNull();
The question has already been answered, but I had this same error message and could not understand why FluentAssertions had made so many changes from 4 to 6 version. Turned out, I had multiple versions of the Nuget package installed. So check via "Manage nuget packages" for solution, if you have multiple versions of the Fluent Assertions nuget package installed. See the consolidate tab in Visual Studio.

Error loading Ninject component ICache with Microsoft.AspNet.Identity 2.2.0

With the recent update of Microsoft.AspNet.Identity.* to 2.2.0, NInject is not working properly anymore.
I get the following error (not finding any services registered in NInject)
Error loading Ninject component ICache
No such component has been registered in the kernel's component container.
Everything used to work just fine with the version 2.1.0. Could it be a bug introduced in Microsoft.AspNet.Identity? Or a remnant bug from NInject (if so, which package?)
Really similar to Error loading Ninject component ICache, but this just started happening since version 2.2.0
I use latest of all NInject on NuGet.
NInject 3.2.2.0
Ninject.MVC3 3.2.1.0
Ninject.Web.Common 3.2.3.0
Ninject.Web.Common.OwinHost 3.2.3.0
Ninject.Web.Common.WebHost 3.2.3.0

Global.Asax error in MVC4 Web API runnin in Azure compute emulator - only sometimes

I noticed yesterday that this error was happening in my local Windows Azure emulator when I debugged my web role. But the deployed project still worked on Azure. Today, my deployed project is failing with this same error. HELP PLEASE!
This code block in my Global.axax.cs file's Application_Start method:
GlobalConfiguration.Configuration.MessageHandlers
.Add(new BasicAuthMessageHandler()
{
PrincipalProvider = new PrincipalProvider()
});
throws this error:
Inheritance security rules violated by type: 'System.Net.Http.Formatting.JsonContractResolver'. Derived types must either match the security accessibility of the base type or be less accessible.
when I start debugging (this is an Azure web role project). But only sometimes (actually it seems to happen every OTHER time I debug) ... and all I have to do to fix it is to stop and re-start the debugger. What is causing the problem?
This had something to do with the Newtonsoft.Json assembly. I deleted it from my project's references, cleaned and rebuilt the project (for good measure), and then re-added it and rebuilt the project again. The error went away.
System.Net.Http.Formatting.JsonContractResolver is derived from Newtonsoft.Json. Another thread (here: http://forums.asp.net/t/1812274.aspx/3/10) addressed this same problem by removing Newtonsoft.Json from the GAC, since it was there and System.Net.Http.Formatting was not. This apparently solved a person's problem, although it seems backward to me (why can't the base type be in the GAC while the derived type is not? Isn't the error saying the problem is the other way around??).
Try updating your nuget packages. I updated mine, and it fixed the issue. I was also having this issue on azure service itself.

Ninject and MonoDroid

Anyone had any luck getting Ninject to work on MonoDroid? i've tried the 2.0 and 4.0 mono builds from their website and also tried the .net versions.
With the Mono builds i'm getting a MissingMethodException in the instantiation of my StandardKernel
I am experimenting with Ninject on a combined WP7/Monotouch/Mono for Android project and Ninject works surprisingly good.
I used the latest sources, which contain a project file Ninject.WP7.csproj which seems to be outdated. It contains a lot of DefineConstants. I created new WP7/Monotouch/Mono for Android solutions with these constants and everything compiled and works!
Constants used:
SILVERLIGHT,SILVERLIGHT_40,NO_LCG,NO_ASSEMBLY_SCANNING,NO_WEB,NO_PARTIAL_TRUST,NO_SKIP_VISIBILITY,NO_EXCEPTION_SERIALIZATION,NO_DEBUG_SYMBOLS
not sure if they are all needed, but the SILVERLIGHT one is important because Monotouch/Mono for Android implement a large part of the Silverlight api.
Of course you cannot create Android Activities with Ninject. I use it mainly for constructor injection, to create .Net objects like a ViewManager, view models using a repository, etc., the usual things you do with dependency injection.
I haven't tried to get Ninject working, but I'd be very surprised if it just worked out of the box. If there's a Silverlight build of Ninject you may have more luck with that, but there are no guarantees. The "best" way to get support for it in Mono for Android would be to build the code against the Mono for Android profile as a class library.
That said, there are other options out there for doing service location in your apps. I have a blog post up here that talks about using TinyIoC and Funq for service location.

"No endpoint configuration found in scanned assemblies” for copied NServiceBus project

I made my NServiceBus solution and it was all working. I then moved one of the projects to a different solution.
When I run them in that solution I get this error:
No endpoint configuration found in scanned assemblies. This usually happens when NServiceBus fails to load your assembly contaning IConfigureThisEndpoint.
I have a class in the project I am trying to get running that looks like this:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
}
I fully copied the folder that contained this project when I moved it to the new solution. (So this is the exact same class that is in the original and the original worked perfectly.)
I am not sure what to do, so I did a bit of googling and came up on this question.
Based on the answer there, I have tried this:
Make sure that there is a class that implements IConfigureThisEndpoint
Make sure that only one class implements IConfigureThisEndpoint
Make sure that the NServiceBus libraries I am using are .NET 4 libraries
Make sure that the implementing class is public (see code above)
I don't do any non-default actions with regards to signing so delay-signing should not be an issue
Any ideas what would cause this error (besides what I have tried) would be great!
UPDATE:
I remembered that I had used the Modeler to setup the dependencies in the original project and NuGet to do it in the copied project.
So I went and compared versions. The Modeler based project was using NServiceBus 2.5.0.1496. When I used NuGet to upgrade that to NServiceBus 2.6.0.1505 (what I had in my copied project) I started getting the same error (in my original project that had previously worked just fine).
So I copied the working DLLs into my broken project and it all started working.
So I can only conclude that this is a version issue. Something with how I have set things up (defaults for the Modeler) is not compatible with version 2.6 of NServiceBus.
NuGet does not have history of the same version of NServiceBus as the Modeler tools has. I think this is an error because NServiceBus packages don't reset the build (last) number. And there is a NServiceBus version
2.6.1496,
but not a
2.5.1496
like what comes with the modeler (there is a 2.5.0.1490, but close only counts in horseshoes and hand grenades).
So I am going to have to abandon NuGet for NServiceBus (because I need the exact version that is in the Modeler or I have to figure out why I am getting this error.)
If anyone has a better way to deal with this problem I would LOVE to hear it.
I remembered that I had used the Modeler to setup the dependencies in the original project and NuGet to do it in the copied project.
So I went and compared versions. The Modeler based project was using NServiceBus 2.5.0.1496. When I used NuGet to upgrade that to NServiceBus 2.6.0.1505 (what I had in my copied project) I started getting the same error (in my original project that had previously worked just fine).
So I copied the working DLLs into my broken project and it all started working.
So I can only conclude that this is a version issue. Something with how I have set things up (defaults for the Modeler) is not compatible with version 2.6 of NServiceBus.
NuGet does not have history of the same version of NServiceBus as the Modeler tools has. I think this is an error because NServiceBus packages don't reset the build (last) number. And there is a NServiceBus version
2.6.1496, but not a
2.5.1496
like what comes with the modeler (there is a 2.5.0.1490, but close only counts in horseshoes and hand grenades).
So I am going to have to abandon NuGet for NServiceBus (because I need the exact version that is in the Modeler or I have to figure out why I am getting this error.)