I am using Visual Studio 2013 and haved opened a Project in MVC 5.
I wanted to have dynamic breadcrumbs in my website.
I searched Google and found the question related to mine on stackoverflow.
http://stackoverflow.com/questions/1066777/how-can-dynamic-breadcrumbs-be-achieved-with-asp-net-mvc
So i went for SiteMapProvider, i installed the package using nuget, but after installing it i am getting this following error.
The SiteMapLoader has not been initialized.
Check the 'MvcSiteMapProvider_UseExternalDIContainer' setting in the AppSettings section of web.config.
If the setting is set to 'false', you will need to call the MvcSiteMapProvider.DI.Composer.Compose() method at the end of Application_Start in the Global.asax file. Alternatively, if you are using .NET 4.0 or higher you can install the MvcSiteMapProvider.MVCx NuGet package corresponding to your MVC version.
If the setting is set to 'true', you must set the SiteMaps.Loader property during Application_Start in Global.asax to an instance of the built-in SiteMapLoader type or a custom ISiteMapLoader instance. This can be achieved most easily by using your external DI container.
Ninject is Also installed. i am not sure why i am getting the error. i have not done any settings only installed.
As in this below link there was no settings needed.
http://maartenba.github.io/MvcSiteMapProvider/getting-started.html
How to fix this error and make breadcrumbs work.
I faced similar issue, solved it by installing the MvcSiteMapProvider.MVC5.DI.Ninject package
https://www.nuget.org/packages/MvcSiteMapProvider.MVC5.DI.Ninject/
To use Ninject with MvcSiteMapProvider some configurations and classes are needed which are installed by this package.
I also didn't do any configuration, worked for me at first run.
Related
I'm trying to use Simple Membership in an MVC 5 project. I followed a video tutorial on a test project on my machine and was able to get it to work. Now I'm ready to implement it on a new website but when I get to the step of making a reference for Webmatrix.Data and Webmatrix.WebData I don't have the option in the References/Assemblies/Extensions section. I went to NuGet and tried to add WebMatrix and saw where is said it was legacy and to use AspNet.WebPages.WebData which I then installed through NuGet. Still no reference available for Webmatrix.
So, I looked at the references of the project that was working and found that there was a Packages/Microsoft.AspNet.WebPages.WebData.3.2.3 folder and copied that to my current projects folder. I then made a manual reference to the WebMatrix.dll in that folder and made sure that it was listed in my packages.config file like my working project. That seemed to have fixed my issue where it my pages were referencing the System.Web.Security.
However, in my Global.asax page I need to have the following
WebSecurity.InitializeDatabaseConnection("DbConnection", "Users", "UserId", "UserName", autoCreateTables: true);
I'm getting an error with that. It says 'object' does not contain a definition for 'InitializeDatabaseConnection and the using WebMatrix.WebData is grayed out at the top. When I type WebSecurity and look at the options through intellisense I have very few options and InitializeDatabaseConnection is definitely not there. I can see the reference to WebMatrix.Data and WebMatrix.WebData listed in my References section and there doesn't seem to be any errors associated with that.
I've tried to do some Google searches and can't find anything about the issue. I've been at this for several hours and I'm pulling my hair out trying to get this to work. Please, any suggests would be really helpful...I'm at a complete loss.
I had NuGet install Microsoft.AspNet.WebPages.WebData, Microsoft.AspNet.WebPages.Data and Microsoft.AspNet.WebPages (all v3.2.4).
Then I added a reference to WebMatrix.WebData by browsing to the package (.....\packages\Microsoft.AspNet.WebPages.WebData.3.2.4\lib\net45\WebMatrix.WebData.dll).
And everything worked fine, with
using System.Web.Security;
using WebMatrix.WebData;
Thanks in advance for your help, I appreciate it!
I am looking for some direction on successfully referencing a normal (Non-ASP NET) Class Library FROM an ASP.NET 5 project and have it successfully publish. The catch is that the Class Library uses references to packages brought in from Nuget.
Here are the details and how to reproduce:
New ASP.NET 5 Solution and Website.
Change reference to dnx46
Remove dnxcore.
Add a new Class Library and target .NET 4.6.
Add a nuget package to the Class Library (For Example, add EntityFramework 6.1.3)
Issue Command "dnu wrap .
Add the dependency to the the web project.json:
"frameworks": {
"dnx46": {
"dependencies": {
"ClassLibrary": "1.0.0-*"
}
}
}
At this point, we have the "ClassLibrary" "wrapped" in the "wrap" folder.
The solution and project starts up without an issue, all dependencies are found and resolved. Everything compiles and it runs on IIS Express without issue.
Now if you try and perform a "Local Publish" to deploy to IIS, it will complain that the reference to "EntityFramework 6.1.3" found within the "wrap" project.json cannot be resolved.
After trying this out multiple ways, I think it's because the "EntityFramework" DLL from the nuget packages folder never officially gets wrapped. Somehow this doesn't cause an issue when running on IIS Express but causes an issue when publishing. Although I've used "EntityFramework" as an example, you could have used any reference from Nuget.
Has anyone experienced this before, and if so, how did you resolve it?
My computer unexpectedly crashed while I was working in visual studio on a web application. As a result my csproj was completely corrupted, so I had to start a new web project and re-add all the files and assemblies from my old project.
But for some reason Route, which should be in System.Web.Http, and ResponseType, which should be in System.Web.Http.Description cannot be found, even though I still have the appropriate usings for them. Also, my project is still referencing System.Web and System.Web.Http, and all the other stuff in my application seems to not be generating any errors like this at the moment.
I've also tried writing out the full path to these classes (i.e. System.Web.Http.Description.ResponseType) but while intellisense is able to explore the namespace, the Route and ResponseType attributes are missing.
I'm not sure if this is related, but when I right-click on Controllers and select Add, I don't get an option to add a controller any more. Something got really messed up with this project...
You should re-install the necessary packages to enable Attribute Routing.
From the Tools menu in Visual Studio, select Library Package Manager, then select Package Manager Console. Enter the following command in the Package Manager Console window:
Install-Package Microsoft.AspNet.WebApi.WebHost
Then after manually adding relevant references (i.e System.Web.dll and System.Web.Http.dll if they aren't already referenced) and using proper namespaces, your attributes should work:
using System;
using System.Web.Http;
using System.Web.Http.Description;
As an alternative to the accepted answer, I found that it was possible to automatically have the necessary packages installed as soon as the first Web API 2 controller is added to the project through the solution explorer's context menu.
Resolve for me by doing the following!
Save the solution
update-package -reinstall
I am working on an Asp.Net MVC 4 Application in which I am using SignalR 2.0.1 and I Mapped it using Owin Startup class and it worked fine at first.
All of a sudden when I tried to rebuild my app it said that the type are namespace IAppbuilder could not be found.
Following is my start up class
using Microsoft.Owin;
using Owin;
using WhiteBoardApp;
namespace WhiteBoardApp
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
I have installed Owin package too, and for some reasons I could not find Owin Startup class so I just added a normal class and included all the references that are needed.
May I know where I am making a mistake
Try to use Package Manage Console and do
Update-Package Owin -Reinstall
I was having similar issue. But instead Owin, problem was causing Microsoft.Owin, obviously
Update-Package Owin -Reinstall
Didn't work, neither did Update-Package Owin
BUT
Install-Package Microsoft.Owin
did work fine for me, thanks.
The IAppBuilder interface is found under Owin package. Just add a reference in your class file:
using Owin;
And rebuild. Your project will pick this up.
I have no idea why VS didn't pick this up, but it didn't. Once I added this reference to my project, then everything fell into place.
I encountered the same problem while building my project. Here are the steps that helped fix my problem:
Go to Solution Explorer and look for your project
Under your project, expand the References; You should see warnings on the problematic reference
Right click References and open Manage NuGet Packages
Search the name of problematic reference i.e. Microsoft.Owin; After loading it shows that it is already installed (It is, but it installed incorrectly. Checking the properties > version at step 2 shows 0.0.0.0)
Check Force uninstall, even if there are dependencies on it
Uninstall
Install
Build and run the project
Problems
Cannot install Microsoft.Web.Infrastructure because it already exists in the packages folder. Rolling back...
Go to your project folder and look for packages
Find the problematic package i.e. Microsoft.Web.Infrastructure
Delete the folder
Resume from step 7
Alternatives
Here are the alternatives I've read about to fix this kind of problem.
Clean and Rebuild Project / Solution
Restart Visual Studio
Restart PC
Good luck.
My Visual Studio 2013 for some reason didn't realize that the references paths existed. The yellow exclamation mark in front of the references was shown for all the added packages. I checked ../packages/ but all files existed, i also opened the .csproj file which referenced the correct paths.
Closing and opening the solution returned quite a lot of errors, and could not load the projects included in the solution.
Restarting Visual Studio 2013 saved the day for some unexplained reason.
My following using's equivalent in F# present a problem of hiding the IAppBuilder. It turns out that the Owin stipulation was being interpreted as an incomplete System.Web.Http.Owin reference, even though the Owin.dll providing the Owin namespace was referenced.
open System.Net.Http
open System.Web.Http
open Microsoft.Owin
open Owin
The problem was resolved by rearranging the usings as follows:
open Microsoft.Owin
open Owin
open System.Net.Http
open System.Web.Http
...granted, this may be a bug peculiar to the F# compiler and name conflicts are handle better in C# and elsewhere.
In my case, I had moved around the project folders and the location of the vs solution file (.sln). Once I was done with re-adding the projects, there was a packages folder on the solution level and one was left in a project sub folder.
This way, in that project, the relative package folder links in the .csproj file got messed up.
The reinstallation or other tips regarding the nuget package manager in this thread were helpful. I noticed, that after I reinstalled a few packages, in my git source code diff, the path of the packages folder was changed within the csproj file.
Before
<HintPath>packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
After
<HintPath>..\packages\Microsoft.Owin.4.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
So, if you run in the same issue and you have a lot of nuget packages, it might be easier to close the whole solution, open the csproj file(s) in a text editor like vscode and fix the relative links with search and replace. Then just save, close, reopen solution in VS and restore nuget packages. That should do the trick.
(In any case, you should delete the local packages folder on the project level, so that the project really fails, if it does not get the right packages.)
It's an ordering issue.
using Microsoft.Owin;
using Owin;
Leads to Microsoft.Owin to be defined first, then Owin is found under already imported Microsoft namespace. If you mouse over Owin of using Owin you should see it was resolved to Microsoft.Owin again and furthermore IDE will gray out using Owin as redundant unused reference.
Do:
using global::Owin;
Which clarifies for the compiler not to look for Owin under already defined namespaces (e.g. Microsoft. namespace).
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
Check for the visual studio you are using
You can find the following comment
Note: If you are using Visual Studio 2012, the SignalR Hub Class (v2) template will not be available. You can add a plain Class called ChatHub instead.
Also
Note: If you are using Visual Studio 2012, the OWIN Startup Class template will not be available. You can add a plain Class called Startup instead.
I'm trying to use DataAnnotations in my WPF project to specify a maximum length of strings, with the following:
using System.ComponentModel.DataAnnotations;
However, I get the error
The type or namespace name 'DataAnnotations' does not exist in the
namespace 'System.ComponentModel' (are you missing an assembly
reference?)
I've seen other examples where DataAnnotations does exist in this namespace. I'm using C#4. Is there any reason why I can't use this? What can I do to fix it?
You have to reference the assembly in which this namespace is defined (it is not referenced by default in the visual studio templates). Open your reference manager and add a reference to the System.ComponentModel.DataAnnotations assembly (Solution explorer -> Add reference -> Select .Net tab -> select System.ComponentModel.DataAnnotations from the list)
If using .NET Core or .NET Standard
use:
Manage NuGet Packages..
instead of:
Add Reference...
To Reference System.ComponentModel.DataAnnotations
In a code file to have Using System.ComponentModel.DataAnnotations; at the top of the file such as:
using System.ComponentModel.DataAnnotations;
Add a .NET reference to your project by right clicking the project in solution explorer:
Hope this helps! This question helped me.
If you don't have it in references (like I did not) you can also add the NuGet System.ComponentModel.Annotations to get the assemblies and resolve the errors. (Adding it here as this answer still top of Google for the error)
I also had the same problem and I resolved by adding the reference in one of my projects which didn't had the mentioned reference. If you have 2-3 projects in your solution, then check by adding this reference to the other projects.
I found that I cannot reference System.ComponentModel.DataAnnotations from Silverlight 5 with the below version at (1). I found that Silverlight 5 assemblies cannot use .NET assemblies, it gives the error "You can't add a reference to System.ComponentModel.DataAnnotations as it was not built against the Silverlight runtime. ..." I plan to workaround this by hopefully installing the Silverlight 5 package found at (2) below. If this fails I will update this post.
[UPDATE: it failed. I installed everything relating to Silverlight 5 and I don't have the Silverlight version of the .dll assembly System.ComponentModel.DataAnnotations . Too bad. UPDATE II: I found an old .dll having this name from a previous installation of Silverlight developer's kit for Visual Studio 2008 or 2010. I added this file and it seems to 'work', in that IntelliSense is now recognizing attributes on class members, such as [Display(Name = "My Property Name")]. Whether or not this works for everything else in this .dll I don't know.]
(1)
Microsoft Visual Studio Professional 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.51641
Installed Version: Professional
(2)
http://go.microsoft.com/fwlink/?LinkId=229318
I searched for help on this topic as I came across the same issue.
Although the following may not be the Answer to the question asked originally in 2012 it may be a solution for those who come across this thread.
A way to solve this is to check where your project is within the solution. It turns out for my instance (I was trying to install a NuGet package but it wouldn't and the listed error came up) that my project file was not included within the solution directory although showing in the solution explorer. I deleted the project from the directory out of scope and re-added the project but this time within the correct location.
Use the FrameWork version 4.5 and above for your project then problem solved.Because this namespace is under 4.5 and above.
System.ComponentModel.DataAnnotations is contained in its own assembly so you need to make sure you have it refernced. Just simply:
1). Right click on Soloution and choose add.
2). Choose reference from the list.
3). Search " System.ComponentModel.DataAnnotation " and tick the check box on its left hand side and press ok.
Job done, shouldnt have any refernce errors.
If you tried to update visual studio from vs2008 to vs2010. And your app uses framework 3.5 (and you don't want to upgrade it), and also used WCF RIA Services BETA... I have bad news... you MUST upgrade to WCF RIA Services v1 (BETA does not work on vs2010)... and due to this... you also have to install Silverlight 4 + upgrade to framework 4.0
See this:
http://blog.nappisite.com/2010/05/updating-visual-studio-2008net-35-ria.html
I upgraded from Silverlight 4 to Silverlight 5 and then I was having this issue. Although I had a reference to "System.ComponentModel.DataAnnotations" under "References" in my project, it had a yellow yield sign by it that indicated the previously referenced assembly could not be found. It turned out that the properties of the "System.ComponentModel.DataAnnotations" reference indicated "Specific Version = True", when I changed this to "Specific Version = False" it fixed the issue. Right click on the "System.ComponentModel.DataAnnotations" assembly under "References" and select "Properties" from the context menu. Check that the property value for "Specific Version = False".
It must have been referencing the old Silverlight 4 assembly which was no longer available after the upgrade to Silverlight 5.
I also have this problem.
That is very stupid when i add a namespace the same with System. I try to remove all references, but it is not resolved. I use "global::System.ComponentModel", it is working as well.
When i remove my namespace, this problem has been resolved.
For .Net Core in Visual Studio 2019 try this.
see VS suggestion
It worked for me, hope it'll work for you as well.
I was moving from .Net Framework 4.7.2 to .Net Standard 2.0.
In my case, I had to change DataAnnotations's reference from an Assembly reference to a Nuget package.
This error occurs when the reference to the "System.dll" got removed.Solution to the problem is very simple add the reference to "System.dll".The dll is normally available in the following location
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" .Add the reference your problem will get solved .
There was a problem using System.ComponentModel.DataAnnotation in net40 so I just did:
#if !NET40
using System.ComponentModel.DataAnnotations;
#endif
#if !NET40
[StringLength(256)]
#endif
The NET40 must be a predefined macro definition for .Net Framework 4.0
I had same problem, I solved this problem by following way.
Right click on page, select Property. in build action select Content.
Hope that this solution may help you.