' Sequence contains no elements' exception when initializing ninject - c#

I have a problem with Ninject which I have not seen before and don't know how to fix. I am using the MVC NuGet package for MVC 5.
In my NinjectWebCommon.cs, there is the following method:
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
However, it falls over when trying to execute the last line, complaining that the "sequence contains no elements". I was previously using Unity for DI but have changed to Ninject.
Any ideas?
Thanks in advance, M

In my case, my project had two NinjectWebCommon.cs folders with the same/similar content.
Dropping the folder has resolved the issue.

I faced this type of error while preparing a new solution by replacing File Name and other text in Entire solution.
Everything was perfect like buld the application.
But when i go to run the application it says me "Sequence contains no elements" error.
And finally i finally resolve that issue by using following.....
open every project folder by right click on the project >> Then select "Open Folder in File Explorer
Remove 'bin' and 'obj' folder
Clean Entire project
Build application
and finally run the application.
Hopefully, it will work for you....
Thanks...

For my two penneth and related to #Pavan's post. I started receiving the error after renaming an assembly. I had the old DLL lingering in the bin folder. Cleaning the solution didn't fix it. I had to go in and delete the contents of bin by hand.

I think this is a dupe of this question: Ninject + MVC3 = InvalidOperationException: Sequence contains no elements
TL;DR - make sure you clear out all old dlls when you publish your site.

An additional explanation detail to extend the helpful answer by #Greg_B:
A reference to another project in the solution that also uses Ninject. Removing this reference solves the problem.

Related

Where is index.g.cshtml

I am trying to work through this tutorial, ASP.Net Core Razor Pages, but (often) when I build the solution, I get a CS0234 error stating that a namespace is missing from file Index.g.cshtml.cd, but where does this file exist?
I have tried
All the build/clean/rebuild solution options.
I have restarted Visual Studio
I have deleted the DEBUG files and restarted VS and FINALLY
I have restarted my PC.
The ONLY solution that seems to work, is to delete the entire solution/project and start again.
Surely there must be a fix for this?
Can you assist?
If an error says a using directive or namespace is missing from xxx.g.cshtml.cs, that usually means, that there is a directive directly in the view (.cshtml or .vbhtml), that the compiler cannot resolve.
In my case I had the following statement in a partial view:
#inject UserManager<AppUser> UserManager
I then went along and refactored the AppUser class from the web application Namespace.Web.AppUser into Namespace.Entities.AppUser, which then was causing that error.
There are different ways to resolve this.
The easiest way is to use a fully qualified type namespace:
#inject UserManager<Namespace.Entities.AppUser> UserManager
And do not forget to add a reference to the other project, if it is in another project.
Or: add a using statement:
#using Namespace.Entities;
Or: Add the using statement above to your ~\Views\_ViewStart.cshtml. This will make that class available in all views.
I landed here with the same errors with Visual Studio 2019 16.2.2. For me, I had changed the name of some of the models and rather than picking up the error in the actual views which were using the models, the error showed in page.g.cshtml rather than page.cshtml.
So, my solution was rather simple. If the error was in page.g.cshtml, ignore the g, go to the view page.cshtml, update the model name to the correct name, rebuild and errors gone.
right click your project and open folder in Explorer. Then search for "Index.g.cshtml.cs"
Then delete the file search results
Make sure your Index.cshtml is referencing the correct model.
Recently I have faced the same issue,
Try the following simple method
copy the error and paste it in the notepad. There you can able to see the original root cause path of the error file, e.g 'YourProjectFolder'\obj\Debug\netcoreapp2.2\Razor\Views\'View Name'\index.g.cshtml.cs
Locate the file, if the error really persists refer the correct namespace in your index.cshtml file else delete the file and rebuild.
Also check you have any duplicate file and which was excluded from the project. If it is exists delete the file too
Now clean and rebuild the project. (You may need to clean, close VS, rebuild)
If your solutions keeps failing because of those .g .cs files, it could be because you forgot to update the namespace of a class that you may have moved, in the actual cshtml file (example via an injection of the said namespace).
This is what solved the issue for me:
https://til.secretgeek.net/.net_core_MVC/error_in_g_cs.html
you can try below solution
Go to C:\Temp\msbuild
2.There you would find folder with your project name and inside those folder you find these files as shown in below image
Try to delete those files and rebuild your solution that might help you
There is actually no real answer to this question.
It turns out that the file is create inside the DEBUG folder.
However, after deleting the Debug folder, I was still getting the error.
So it must be a VS bug?
Try to clean all the obj folders in all of your projects and build again. This is part of the code that is generated by the compiler, sometimes it is not synchronized with the view itself, even Rebuild that should clean everything doesn't work. Do it manually. Hope this helps
It's Microsoft.AspNetCore.Razor.Design Package issue.
I tried with 2.2 version in my VS2017 which does not support this and gives ".g.cshtml not found" in obj directory.
I solved issue as below:
I downgraded ASP.NET Core version of my project 2.2 to 2.1
Changes done in startup.cs:
CompatibilityVersion.Version_2_2 to CompatibilityVersion.Version_2_1
Change all dll of Nuget packages to 2_1 supportive dll
SDK make sure its 2.1.x
and issue resolved.
Add full namespace in _ViewImports
#using Microsoft.AspNetCore.Http
May be my answer is something late, but hopefully it will help someone:
I have faced the dame issue because I have changed the Project name and later I tried to change the namespaces inside controllers and models, then I found out there is a direct mentioning of the namespace inside (Pages/_ViewImports.cshtml) from there I updated them to match the namespace used inside my models and the issues gone. ViewImportsImage
Now my ViewImports.cshtml content looks as follows:
ViewsImport.cshtml content

How to resolve reference solutions dependencies

Work on C#.Stuck on my application architectural issue.Have two solutions named CalculationManager and ContainerManager.
ContainerManager have reference of CalculationManager and CalculationManager hold other three class library references like the picture.
Problem is ContainerManager debug perfectly but when run this project show error message Could not load file or assembly.
What to do ? how to break this CalculationManager’s dependencies? Have no idea what to do?
Check your bin folder in ContainerManager.
AdditionManager, MultiplyManager and SubtractionManager dll's should've also been added along with ImplementationManager, if not then there's the problem.
Hope this helps.

Trying to add a reference to my solution

I am a complete stranger to adding "custom" references to my projects, usually everything I need I can find in NuGet packages. Ive come across a problem and the solution I've found is to add the following reference to my project:
https://microsoftdwayneneed.codeplex.com/
Ive downloaded the source code, opened up the project in VS and hit build. I then went into the bin/Release folder and added the .dll for both Win32 and normal which I assume is any CPU.
The problem I faced earlier is now fixed, however now a new problem arised: I keep getting the message that the Microsoft Visual Studio XAML UI Designer has stopped working. The error it gives is a NullReferenceException and in the name is "dwayneneed" so I can only assume that I messed up adding the reference.
Can someone explain to me how to add references like the one above correctly to my solution.
The problem Im trying to solve for those wondering:
https://github.com/MahApps/MahApps.Metro/issues/488
the solution, see: https://github.com/MahApps/MahApps.Metro/wiki/FAQ
Do you mean adding a solution to the solution, like this.

Schema specified is not valid. Errors: Multiple types with the name

I am working in EF 6 and facing the following issue when I try run my project.
Schema specified is not valid. Errors:
Multiple types with the name 'TableName' exist in the
EdmItemCollection in different namespaces. Convention based mapping
requires unique names without regard to namespace in the
EdmItemCollection.
I tried too much on StackOverFlow and google and found no solution. I am using visual studio 2012. I crated a single .edmx file for whole of my database. I searched the tableName throughout the project and there is single occurrence of table.
Please help me in this regard
Finally I figured out the solution of the problem.
In my question above, I stated that I have only single edmx file in my project. It is true in one sense. But wrong in the other sense.
I am using git to manage my code. I created another edmx file in another project and used that project's reference in my main project.
Then I switched git branch with dll in .gitignore. Those dlls which were in .gitignore could not be replaced by git with the newly switched branch's dlls.
So I had two references of edmx files in my project with fully built dlls.
Problem solved when I keenly checked my bin folder and removed the dll which was actually not belonging to the current git branch.
I hope it will help you.
Comment here if some thing is not clear.
Thanks
I spend hours fixing it, tried publishing/deploying all the projects but no luck. So, finally found out that there was a dll that was referenced twice. But with slightly change in name but pretty much similar content. So, program wasn't sure which file to look at. I redeployed all the projects but still no luck. So, finally deleted all the files from server except webconfig and global asax. And the deployed the files again. Finally it worked.

SCSF Recipe Framework Error

I am experiencing a random issue with the SCSF 2010 guidance package when I try to add a View with Presenter in my VS2010 project. This also happens when I try to add a Business Module as well.
The issue seems to happen randomly because the same exact solution opened in two different locations, one will let me add views and the other one will throw the exception. Its really mind boggling. Sometimes it will let me add Views no problem, sometimes it just crashes.
I have to check out an earlier version of my solution from source (which I know will let me add views) and create everything and import it into the most current version.
It seems to be related to this WCSF issue but I had no luck with the solutions proposed here.
http://webclientguidance.codeplex.com/discussions/263101
Deleting the gpState and re-enabling SCSF did not help.
This is the error:
Microsoft.Practices.WizardFramework.WizardExecutionException: The wizard failed to execute. The error was:
Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider'. ---> System.InvalidCastException: Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings' to type 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider'.
I believe this is the answer to your problem.
The problem can be resolved by removing a Page Flow project and the Page Flow settings in web.config (including connection string and http modules).
Which you can find here.
Recipe Framework Error when adding page with presenter.
... some users have also suggested that deleting the .gpState file of the solution, re-opening the visual studio & solution and re-enabling WCSF Guidance seems to fix this problem temporarily. Please, create a backup of your .gpState file before trying this approach.

Categories