MVC 4 Add Controller Error Unable to retrieve metadata for my Model - asp.net-mvc-4

I recently added a MVC4 Web Application to my solution and gave it a reference to my Common class library. The Common class library contains the models and context (EF Code First).
When attempting to use Visual Studio's scaffolding feature to "Add Controller" to the MVC4 Application, I get the following error:
Unable to retrieve metadata for 'Common.Models.MyContext'. Unable to
load one or more of the requested types. Retrieve the LoaderExceptions
property for more information.
I have found a lot of similar questions on stack overflow, but none of them address this specific error message for this specific scenario.
In my investigations, I found that if I remove all the added packages and third party dll's from the Common library, I am able to use the "Add Controller" function without error. This tells me that one of my packages or third party dll's is not where it needs to be (as indicated by the error message).
So my questions are these:
How do I find out which dll is causing the problem? Is there a Visual Studio scaffolding log file somewhere?
Say that I find the offending dll... Where would the dll need to live to fix the scaffolding error?

Make sure your web application project has ALL the required references from other projects. Just because your Common project has a dependency on a DLL doesn't mean that reference will be copied to your web project. You will have to add the dependant DLLs manually as references with Copy Local set to "true"

If you are using separates projects, check if EF has the same version number!

Related

Change MS VS Intaller Projects programatically

I've created a sample VB.NET (.NET Framework) project for clarity, but have this issue in existing project too. I am puzzled, that it is missing any type of ProjectInstaller.vb (and associated designer and resource files):
So I cannot access initializing method and create event handlers.
I had similar problems with another project, a windows service, but then I finally found the ProjectInstaller.vb in the associated project (it would be "HelloWorld" in this case):
What do I do wrong and what to do to bring the ProjectInstaller.vb to life?
Notes:
apart this, installer gets compiled and using it, the packages get installed/uninstalled fine
I do have extension with templates:
I performed search in the solution directory for ProjectInstaller, found no results

Multiple dependencies conflict in ASP.NET Core 3.1 and 6.0 ServiceCollection exists in both

Is there any way to see where the v6 reference is coming from? I have searched for 6.0, checked nuget package references (all 3.1.x)
I can see this issue is only limited to a couple of projects in the solution, but running out of ideas of things to check.
This project uses some base project, via a gitlab nuget repo, and itself builds nuget packages to be consumed again, if that is relevant. The base projects do not exhibit this issue (I have added ServiceCollection to each one, and all resolve to 3.1.15 version when pressing F12).
F12 in this project resolves to v6.0:
but I have no idea why or how to change it.
As expected, there was a reference to .NET Core v6.0 somewhere in the hierarchy chain. However, I did not have an easy way to find it.
Having found a project with the issue, the project file had two sections, the nuget references and project settings. I commented out various sections and rebuilt. Yes, there was multiple more errors as packages/projects were now missing their reference, but crucially I was looking for the error above to disappear. The culprit was one of my base projects, so off to the base solution to continue the investigation.
While it was not needed, I added a line of code ServiceCollection sc to the projects, and worked out which one caused an error. I was able to replicate that error in a couple of projects and followed the same process. I commented out various lines in the project file until I made that error go away. (yes there were many, many more errors, but the absence was the key.
It turned out to be a reference to AutoMapper Dependency Injection v11, which has a dependency on Options v6.0.0!
It would be nice to have a way to trace the source of references as even viewing the AutoMapper refence in the main projects did not show its dependency on the DI part.
Hope it helps someone and saves some time.

.Net Core - referencing another project in solution prevents System and other dependencies from being recognised

I have a solution that contains a number of projects, one is an API, the other is an admin portal.
I'm trying to create another project inside the solution to hold all shared components such as database entities so they can be shared between the API and the Admin Portal.
I've created a new project called 'Common' and selected to use netcoreapp2.2 because if I just select a standard class library then annotations on the Entities don't work.
When I reference the 'Common' project from the 'API' project, which is also netcoreapp2.2, Rider(Mac) is unable to recognise any of the standard packaged used with the project such as System and System.Linq (and many others).
My experience with .Net Core is limited to only this project, so I'm sure I'm doing something wrong, I just can't figure out what it is.
I managed to fix this, I removed the 'Common' project from my solution and re-created it this time selecting the create the project as a Web Application.

Where are the symbols for ASP.NET MVC 4.0 RTM?

I'm trying to configure Visual Studio 2012 to allow me to step into ASP.NET MVC 4.0 source code. (System.Web.Mvc.dll). I've followed SymbolSource's recommended configuration but when I try to load the symbols, Visual Studio can't locate them.
Recommended configuration
To configure Visual Studio for symbol/server
use, follow these instructions:
Go to Tools -> Options -> Debugger -> General.
Uncheck “Enable Just My Code (Managed only)”.
Uncheck “Enable .NET Framework source stepping”.
Yes, it is misleading, but if you don't, then Visual Studio will
ignore your custom server order (see further on).
Check “Enable source
server support”.
Uncheck “Require source files to exactly match the
original version”
Go to Tools -> Options -> Debugger -> Symbols.
Select a folder for the local symbol/source cache.
Add symbol servers
under “Symbol file (.pdb) locations”. Pay attention to the correct
order, because some servers may contain symbols for the same binaries:
with or without sources. We recommend the following setup:
http://referencesource.microsoft.com/symbols
http://srv.symbolsource.org/pdb/Public or the authenticated variant
(see above)
http://srv.symbolsource.org/pdb/MyGet or the authenticated
variant (see above) (other symbol servers with sources)
http://msdl.microsoft.com/download/symbols (other symbol servers
without sources)
I am aware that the source code is available on CodePlex, however I'm specifically interested in stepping into the code using a symbol server instead of having to unreference Mvc from the GAC and reference a locally built assembly.
Has anyone had success doing this with MVC 4.0?
Just add a symbol server that serves more then just major releases.
Try this one, contains most minor builds.
http://srv.symbolsource.org/pdb/Public
Verify:
Run VS as administrator.
Check that something have been downloaded to your symbol cache directory.
Goto select only specified modules.
Add "System.Web.Mvc.dll"
Set a break point in your code. Start debug.
When break point hits rightclick in callstack on any mvc.dll row. Verify that symbols are loaded.
if loaded, try dubbleclick on one callstack row to open mvc source.
Get back with where you get in trouble.
I will make some refinements to Luke Gumbley's anwser.
Microsoft tries to make a developer's life easier. Whenever it release an MVC version installer, there should also be a Source to download. So people can use the source to explore what is installed by the Installer, as well as to debug the MVC.
Back to the way of downloading the MVC debug info. Your Visual Studio (I use 2010) will never try to download MVC PDB files from the aforementioned servers if you have MVC4 installed on your system. In this case, your Visual Studio will use the MVC from your GAC when you run debugger.
I have tried the way suggested by Luke Gumbley. However, once you uninstall MVC, your MVC project will not be loaded, and you cannot create a new MVC project since the Template is gone. So please don't unistall MVC. If you do so, you still need to reinstall it. This wastes time.
What you really need to do is exit your Visual Studio, run command
gacutil /u System.Web.Mvc
Then go to C:\Windows\Microsoft.NET\assembly\GAC_MSIL, remove or rename the offending System.Web.Mvc folder. After this, lanuch your Visual Studio, and fetch the MVC package from NuGet.
I can't answer on your question directly and provide you URL with symbols (.pdb) for System.Web.Mvc.dll for ASP.NET MVC 4.0, but probably I can help you to solve the problem in another way.
As well known (see here for example) Microsoft provide the current source code of .NET on http://aspnetwebstack.codeplex.com/. In the post it's described how to use the Nightly version of ASP.NET (the current developer state of the code). If you didn't used Git before you can have problems with downloading RTM version of ASP.NET 4.5 (with ASP.NET MVC 4.0) which you could prefer to use instead of Nightly version. Nevertheless the downloading of the full source code of RTM version is easy enough. You need just to know that Git allows to save copy of the code in branches or tagged versions. In the way you can get access (and download it) to some previous versions of the full code. The link for example provide you jQuery 1.8.2 instead of another link get you the latest developer version which can be unstable. So to download the source code of RTM version you just need to choose "v2-rtm" branch and then click on "Download":
You can use the link to select "v2-rtm" branch directly.
I can repeat that it's not exactly what you asked and I know that compiling of ASP.NET source code could be also a little tricky, but I decided do write the information. If somebody would suggest you the better solution it would be interesting for me too.
I had exactly the same issue (correct version but no symbols), but after a day or so of trying everything I've been able to get it working. These are catch-all instructions that worked for me, they may contain unnecessary steps:
Sign up for SymbolSource and follow the VS instructions using the
authenticated URL form
Uninstall all versions of MVC with add/remove programs
Remove MVC assembly from the GAC (the question is about modifying
MVC but the GAC answer is good)
Remove and then reinstall the MVC 4 reference to your project with
NuGet
Start debugging, open the modules window, and cross your fingers
that ‘Symbols loaded’ is next to System.Web.MVC when it appears.
(sprinkle in restarts as you see fit, for me the key final step was reinstalling the NuGet reference)
My theory is that as the GAC library is used at runtime in preference to the local reference, the symbols are not found when they are searched for. By removing MVC from the GAC and then reinstalling the NuGet reference, it seems the local reference is used and the symbols are found. It's counterintuitive as the System.Web.MVC.dll files are binary-equivalent between NuGet and the GAC, although they are dated differently.
I'm not totally convinced though as I tried to do the same thing for Razor and that didn't work.
Let me start with that ReSharper provides a handy dialog to step in the code at any time:
So you get the following code screen if you drill to the source code:
But I became curious to accomplish this by hand. I started with proper pdb configuration:
After that I got the following error:
Next I copied the C:\Users\Andrew\AppData\Local\Temp\SymbolCache\MicrosoftPublicSymbols\System.Web.pdb\CA49C4332DE847FA967F58AFF370B70E1\System.Web.pdb to C:\Users\Andrew\AppData\Local\Temp\SymbolCache\System.Web.pdb (to match the lookup path). After that i encountered this:
And it turned out that the mismatching builds are only good for browsing the source, not debugging. (Current machine has VS2012 RC, hence MVC libraries are not RTM). If they match, you'll the the source.
I still don't know why doesn't the lookup path adjust to symbol configuration. Hope this helps.
I just solved this same problem.
The problem is that the dll stored in the GAC does not correspond exactly to the published pdbs on symbolsource.org. The one on symbolsource corresponds apparently to the latest version available through Nuget, and the one in the GAC must the one installed with .NET Framework 4.5. (.Net uses whatever is on the GAC before attemting to use anything local to your proyect, you can see this, when debuggin, go the Debug->Windows->Modules, there the System.Web.Mvc.dll is the one from GAC according to its path)
What I did was to include in the GAC the System.Web.Mvc.dll on the package folder of my solution, the one downloaded through Nuget. This you can do by using gacutil on a VS Command Prompt (run the VS Cmd as admin).
You can check on the same Modules Windows, right clicking on the System.Web.Mvc.dll, and then on Symbol Load Information. With the "old" GAC dll you get a message like (part of it)
SYMSRV: http://srv.symbolsource.org/pdb/Public/System.Web.Mvc.pdb/1E540B87149F4031B9CDEACAD8D771231/System.Web.Mvc.pdb not found
Notice here the subfolder 1E540B87149F4031B9CDEACAD8D771231 (yours might be different)
After replacing the GAC dll for the one recently downloaded through Nuget, the message is
SYMSRV: System.Web.Mvc.pdb from http://srv.symbolsource.org/pdb/Public: 336067 bytes
http://srv.symbolsource.org/pdb/Public: Symbols downloaded from symbol server.
C:\Users\\AppData\Local\Temp\SymbolCache\System.Web.Mvc.pdb\68B2330E48624B6C9DE05BED1C8C320F1\System.Web.Mvc.pdb: Symbols loaded.
Notice the subfolder 68B2330E48624B6C9DE05BED1C8C320F1, which is the one that is searched for in symbolsource.org is the correctly found.
Hope this helps
There's some related info here: http://aspnetwebstack.codeplex.com/discussions/399312
And here: Debug into nightly build of ASP.NET MVC4 using Symbolserver

Unable to compile workflow-project

I have a build-server running CC.Net. So far I never had any problems compiling projects on the build server (which has no VS installed, just use the .Net Framework).
But now I have a new projects and I get this message:
C:\Program Files\MSBuild\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets(127,5): error : Compilation failed. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Has anyone any hint's on what's causing this problem?
What might be of some interest is the fact, that this is a SharePoint project wich includes a SharePoint workflow. But this shouldn't stop the project from being able to be compiled.
The problem with LoaderExceptions described here sounds like what you are seeing. Maybe targeting 3.0 instead of 3.5 does fix your issue too.