How to modify code in Microsoft.AspNetCore.Server.Kestrel and then refer to it from elsewhere? - asp.net-core

I'd like to (try to) add HTTP/2 support to Kestrel - for my own edification, for now. I'm using Ubuntu as my dev platform, because my requirements include using Linux.
Of course, it appears fairly simple to make changes to the Kestrel code - just clone the source from https://github.com/aspnet/KestrelHttpServer, then make my changes, then build the assembly. The problem I'm having, is getting other code to reference my modified code/assembly rather than the "official" assembly from .NET Core. To that end, I would love to hear how to do the following:
"Install" my changed Kestrel assembly locally such that anything that depends on that assembly uses my changes automatically. This may include projects that I create via dotnet new -t web, as well as other .NET Core assemblies that I haven't modified.
Be able to propagate my changes to other machines as necessary, in a controlled manner.
Thank you, and have a good one!

There are 2 options
create own nuget package from sources using dotnet pack command, and then use own feed for nuget restore. See related SO answer and Hosting your own nuget feed guide;
or
add Kestrel project into your solution and add dependency as "project reference".

Related

Unable to understand few statements from ASP.NET Core ebook

I have recently started learning ASP.NET Core with the help of an ebook. There are few statements mentioned in the initial chapters, which I am unable to understand clearly.
For eg. following statements are mentioned under Foundational improvements in ASP.NET Core section
Lightweight and modular HTTP request pipeline
Ships entirely as NuGet packages including the runtime
Runtime can be installed Side-by-side- allows you to version application along with runime
The above statements are not clear to me probably because of the term "modular HTTP request pipeline" from Point 1 and terms "runtime" and "version application" from Point 2.
Any short explanation or reference to the suitable doc will be appreciated.
Thanks
http request pipeline
They totally rebuild the HttpListener which is also called the http server. Normally you would host your application in iis which would give you tons of functions but is 1 very old, massive sluggish application.
Now on default you run the application as a console which starts up a HttpListener which is called Kestrel in dotnet core.
This kestrel is totally build from the ground up (so modular priciples and barely any technical depth). And is build based on a very vast C++ library called libuv.
The modularity in this means that it has been build in various loosly coupled parts, meaning that you could replace or extend those parts if you want to. For example use a test server for automatic integration tests.
Ships in nuget packages
Normally you would install a netFramework eg: 4.5.0 and you would already get all these system.* dlls eg: System.web.dll
Now all these dll's are nuget packages and bundled into 1 package called netstandard: https://www.nuget.org/packages/NETStandard.Library/.
Multiple runtimes
If you build a dotnet project, it creates Dlls. these dlls can be run by by any OS if that os has installed the dotnet runtime. (basicaly dll is intermediate language and can be run by the dotnet runtime).
You can also build your dotnet project to include the runtime inside your application, so you can run multiple dotnet applications on an OS with different Dotnet runtime versions.
The downside of this last option is that you have to build your dotnet project for every OS specifically. So normally people choose to just build the OS independent Dlls and make sure the right runtime is installed on the OS.

Understanding ASP.NET Core Dependencies and Capabilities

When I use a Visual Studio 2015 template to create a brand-new ASP.NET Core project, I see a couple of unexpected pieces. I'd like to understand these:
By default, the new project targets dnxcore50 and dnx451. I thought ASP.NET 5 / MVC 6 required .net 4.6, so I don't know why dnx451 is one of the default targets.
Regardless of dnx target, the startup.cs file specifies app.UseIISPlatformHandler. I've been running the dnxcore50 target in Docker (i.e. Linux) without any problem, even though Linux does not have IIS. So I don't know what UseIISPlatformHandler does. I can find no documentation for it either.
Can anyone clarify?
Why dnx451 instead of dnx46 is basically IIS's fault, see answer here. Also perhaps the templates run behind because Azure has not yet switched to 4.6? Just a little theory of mine. I'm not sure.
UseIISPatformHandler is again only used for IIS. You can savely remove it if you have no interest in publishing your web app to IIS. You can learn more about the HTTP Platform Handler (which IIS needs) here. And you can learn more about the IIS Platform Handler Middleware from the source code.
Does this make it more clear?

Cannot Apply EF7 Migrations - Could not load file or assembly... because I might not know something about ASP.net 5?

I currently have a web project to host database migrations. It was created off an Empty Website. I'm using .net Core only, but I don't think this matters. I'm referencing rc1, not beta. (At this point, I won't show you my project.json, my data context, or the startup.cs file because I think the issue isn't with those.)
I've managed adding a migration with the usual dnx ef migrations add migrationName command from the command prompt.
At the command prompt, I'm sitting at the directory of my web project. When I try to run dnx ef database update, I got
"Could not load file or assembly 'MyProject'..."
I built the project and it compiles without error. I'm accustomed to seeing a /bin folder that has assemblies, where one of the .dlls is MyProject.dll from ASP.net 4.5.x and before. I don't see this folder or such a .dll anywhere in the project. I think the dnx is looking for that but it doesn't exist.
Should I publish the project first? None of the tutorials out there tell me to do that. I tried to anyway, but even in the artifacts folder of the solution, I cannot find any .dlls besides those that come from Microsoft.
There must be something I'm missing or that tutorials don't say, though I'm aware that those tutorials are probably old.
UPDATE
It turns out that I needed to
Right-click on project > Build.
Check "Produce Output on Build". It is unchecked by default. Those tutorials didn't tell us this important bit of information!
After that, all is well! I was able to migrate to the database.

Interop with unmanaged code in ASP.net vNext

What's the story going to be (if any) around interop with unmanaged code for ASP.net vNext / Core CLR?
The key bits (DllImport and friends) appear to be present to allow for unmanaged code interop, but how would things such as packaging and deployment work in this context? The basic build artifact in vNext / CoreFX no longer appears to be an assembly, but a NuGet package. So in that case, how would we make the new project.json system work so that unmanaged dlls that we're P/Invoking into are also included in the resulting NuGet package?
Or am I talking about scenarios that have not been considered yet (or more disappointingly, not going to happen)?
The story is yet to be fully fleshed out, but there are already examples of how to do this. Ultimately we (the Microsoft teams working on this) are working on some scenarios to enable NuGet packages to better support native content in packages.
To see one example of this, the Kestrel web server has some of its own managed code, plus it includes libuv in its NuGet package for an efficient async IO implementation that is cross-platform.
Because there isn't yet a built-in general solution in NuGet, the build scripts for Kestrel use some custom actions to include the native content in the NuGet package. Then to load libuv there's some code that dynamically figures out which native libuv to load based on the environment in which it is running.
So, yeah, it's a bit messy, but it does work, and this is definitely high on the team's priority list to improve.

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