Today i wanted to create my first Nuget package and i already knew what i would publish to the world. I wanted to make the code that is used to use MEF in Asp.Net MVC 4 and the WebApi (view this post) easy to reuse in other projects. I rewrote the code in a class libary.
After a little google-ing i found a video that explained how to create a Nuget package using the Nuget Package Explorer. After that i created a user at the Nuget gallery so i got my API Key. With this, i had all the information i needed to published my first Nuget package and i have a feeling that it will not be my last :-)
The package can be installed from the Package Manager Console by typing: Install-Package MEF.MVC4
Subscribe to:
Post Comments (Atom)
Hi Kenny,
ReplyDeleteI just grabbed your Nuget package (thank you), but am getting an exception when I attempt to hit a non-existent controller - eg http://localhost/site/foo.
If the foo controller does not exist then I see the following error: Value cannot be null. Parameter name: type.
Here's the stack trace:
[ArgumentNullException: Value cannot be null.
Parameter name: type]
System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality) +263919
System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(Type type, Type metadataViewType, String contractName) +41
MEF.MVC4.MefControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +28
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Hoping you can give me a hint as to what I've done wrong.
Many thanks,
Chris
You need to add the attribute Export at your controller. Otherwise the MefControllerFactory isn't able to resolve the controller that is requested.
ReplyDeleteHi Kenny, Nice article. I have one question though. If I create a BaseController for all my controllers, then do I need to associate the [Export] attribute to my BaseController as well the child controllers ? please see below, my Homecontroller is not importing any types, so I guess the below example is working fine although I have not associated any [Export] attribute to my home controller
Delete[Authorize]
[Export]
public class BaseController : Controller
{
[Import]
private IViewModelProvider _viewProvider;
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.RequestContext.HttpContext.Request.RequestType != "GET")
return;
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
return;
filterContext.Controller.ViewData["BrandsViewModel"] = _viewProvider.GetBrands();
}
}
My Home Controller is as below
public class HomeController : BaseController
{
public ActionResult Index()
{
return View();
}
}
Basicly when your application is requested for non-existent controller MefControllerFactory.GetControllerInstance is called with controllerType=null
ReplyDeleteimmedeately at GetControllerInstance start ExportProvider.GetExports is called with type parameter of null. That is the source of exception, because GetExports requires not null type parameter.
It would be great if Kenny can fix this issue in future releases.
I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it.http://www.chapmanusedcarsaz.com |
Deletehttp://www.automotive-law.com |
http://www.carsearchnew.com |
http://www.fiatfirecars.com |
http://www.pacetransportationinc.com |
http://www.countytransportation.com |
http://www.edgecliffautomotive.com |
http://www.ldptransportes.com |
http://www.steamautospa.com |
http://www.chrusciel-transport.com |
Thanks for this, its great! If I wanted to build controllers in a seperate dll, in which folder would I put it?
ReplyDeleteHi Kenny, Nice article. I have one question though. If I create a BaseController for all my controllers, then do I need to associate the [Export] attribute to my BaseController as well the child controllers ? please see below, my Homecontroller is not importing any types, so I guess the below example is working fine although I have not associated any [Export] attribute to my home controller
ReplyDelete[Authorize]
[Export]
public class BaseController : Controller
{
[Import]
private IViewModelProvider _viewProvider;
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.RequestContext.HttpContext.Request.RequestType != "GET")
return;
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
return;
filterContext.Controller.ViewData["BrandsViewModel"] = _viewProvider.GetBrands();
}
}
My Home Controller is as below
public class HomeController : BaseController
{
public ActionResult Index()
{
return View();
}
}
I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it.SEO Liverpool
ReplyDeleteThis is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works.tartanarmymessageboard |
ReplyDeletemikestoanelighting |
workplace-wellness |
thumbswood |
oldfieldrealty |
utilitysearches |
bizzybooker |
restaurantrecruit |
vetequip |
cafe-vn |
Do you want to market a service or product but lack the knowledge to start? If this sounds like you, Facebook is an easy way to get started. You have the ability to reach millions of people. Keep reading to find out more.
ReplyDeleteLainey
Layton
Leonidas
Lilliana
London
Lydia
Madilynn
Malcolm
Marie
Mason
This comment has been removed by the author.
ReplyDeleteSo what does this mean for the future of Rails dev? gw2 gold Does DHH need to find a new gig?
ReplyDeleteJake
Jase
Jayden
Jenna
Jocelyn
Jordyn
Jude
Justus
Kalel
Karlie
Kayden
Kelvin
Kiera
Konnor
Kyra
Laurel
Lennon
Lila
Lisa
Lucille
Madden
Makena
Marcus
Marlon
Maximilian
Mercedes
Miles
Morgan
Natasha
Nina
Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
ReplyDeleteMarleigh
Maverick
Melody
Milana
Monica
Natalie
Niko
Olivia
Paul
Porter
Randall
Reese
Riley
Rory
Ryann
Samiyah
Scarlet
Shiloh
Sonny
Talia
Terry
Tori
Tyrone
Vincenzo
Wilson
Yusuf
Zeke
Abby
Adeline
Alaina
Between me and my husband we’ve owned more MP3 players over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I’ve settled down to one line of players. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.
ReplyDeleteGracelynn
Hadley
Harry
Holden
Isabela
Jackson
Jamal
Jasper
Jayleen
Jeremy
Johan
Joselyn
Juliana
Kaelyn
Kamden
Karter
Kaylen
Kenia
Kimberly
Krish
Lachlan
Layla
Leonard
Lilianna
Logan
Luke
Madelyn
Malakai
Mariam
Marvin
Purchasing furniture is something that most people will have to be difficult. You just need to be smart about it to save yourself money and time.
ReplyDeleteMckayla
Michael
Miranda
Myla
Neil
Nolan
Paislee
Peter
Quintin
Raylan
Reuben
Rogelio
Roxanne
Sadie
Sarah
Serenity
Skye
Stetson
Taylor
Tiffany
Tristian
Van
Wayne
Yadiel
Zane
Abrielle
Adriana
Alayah
Alexis
Allen
I think if we put all the logic in the client side, as well as the validation our server will accept all data and it will be so easy to crack the application. How do we handle this without putting validation on the server?
ReplyDeleteMorgan
Natasha
Nina
Orion
Paxton
Prince
Raphael
Reginald
Rivka
Rosalie
Rylan
Sandra
Scott
Siena
Soren
Tamia
Thaddeus
Trent
Uriah
Vivian
Wren
Zackary
Zoe
Addilyn
Aiden
Alec
Aliana
Alonzo
Amira
Angel
Aim for a higher progress and development and work your way from those goals and plans. Interesting in here indeed. thanks for the share.
ReplyDeleteEvalyn
Finley
Gabriella
Giancarlo
Graeme
Haleigh
Hattie
Houston
Isaiah
Jacqueline
Jamarion
Javon
Jaylin
Jerome
Johnathan
Joshua
Julie
Kaia
Kamila
Kash
Kaylyn
Kennedi
Kingsley
Kristina
Lainey
Layton
görüntülü.show
ReplyDeletewhatsapp ücretli show
QQM