Unable to get source to run in my project

Topics: ASP.NET Web API, General
Apr 9, 2012 at 12:37 PM

Hi all, 

I've been struggling for two days to get the source running in my MVC 4 project.

I originally created a MVC 4 beta Web API project. I implemented the custom MediaTypeFormatter as shown by Henrik http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx

After implementing the custom MediaTypeFormatter, I found that a custom model binder I was using the automatically create a model that I use throughout the project was no longer executing for PUT requests. When reverting back to the standard Json MediaTypeFormatter, the model binder began working again. 

I then decided that I'd try to get the latest source and reference that, as I believe the above issue is a known issue that will be resolved for the latest release.

I have done the following:
- Uninstalled MVC 4 Web Platform Installer Bundle
- Installed the MVC 4 Visual Studio Tools seperately from the Developer Preview (so I could open my MVC 4 project in VS)
- Cloned the source using TortoiseGit, Run the "build RestorePackages" "Build" command
- Removed references to all the relevant Assemblies in my MVC Web API project
- Added the source projects to my solution
- Added references to the source projects to my project

I had to change a few things in my project to suit the latest code such as HttpResponseMessage<T> to just HttpResponseMessage etc and my project compiles.

Although when running the project, I'm now getting the following reference error:

 

Could not load file or assembly 'NuGet.Core, Version=1.6.30117.9648, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The stack trace is as follows:

 

[FileNotFoundException: Could not load file or assembly 'NuGet.Core, Version=1.6.30117.9648, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes) +0
   System.Reflection.RuntimeAssembly.GetExportedTypes() +38
   System.Web.WebPages.ApplicationParts.ResourceAssembly.GetTypes() +14
   System.Web.WebPages.ApplicationParts.ApplicationPartRegistry.Register(ApplicationPart applicationPart, Func`1 registerPageAction) +121
   System.Web.WebPages.ApplicationPart.Register(ApplicationPart applicationPart) +51
   System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule() +107
   System.Web.WebPages.Administration.PreApplicationStartCode.Start() +28

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.Web.WebPages.Deployment.PreApplicationStartCode.LoadWebPages(Version version) +245
   System.Web.WebPages.Deployment.PreApplicationStartCode.StartCore(IFileSystem fileSystem, String appDomainAppPath, String binDirectory, NameValueCollection appSettings, IEnumerable`1 loadedAssemblies, IBuildManager buildManager, Action`1 loadWebPages, Action registerForChangeNotification, Func`2 getAssemblyNameThunk) +251
   System.Web.WebPages.Deployment.PreApplicationStartCode.StartCore() +164
   System.Web.WebPages.Deployment.PreApplicationStartCode.Start() +33

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.WebPages.Deployment.PreApplicationStartCode threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +423
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.WebPages.Deployment.PreApplicationStartCode threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090044
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
I can't seem to figure out, why this is happening or where this reference is.
Anyone have any ideas or suggestions? I'd really appreciate any advice.
Cheers,
Glen

 

Apr 10, 2012 at 5:05 AM

I posed a blog on how to get started with the source today:

http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx

Hope it's helpful

Henrik

Apr 10, 2012 at 6:40 AM

Thanks Henrik, 

I'll try to uninstall the MVC 4 VS Tools and see how I go. 

I'll also try creating a blank MVC project and try to get it just to run with the source code and see if the problems I'm experiencing are coming from somewhere else. 

Thanks again for all your help, I really appreciate it. 

Cheers,

Glen

Apr 10, 2012 at 2:36 PM
You need to uninstall MVC 4 itself as well as the tools. The primary problem is that the runtime is installed, since the installer puts MVC and Web Pages into the GAC (and it has the same version number as the assemblies you are building from source).
Apr 13, 2012 at 11:22 AM

Hi Brad and Henrik, 

Thanks both for your help.

I seem to have tried everything and still had no luck. 

I've uninstalled MVC 4 and the VS tools, run the instructions Henrik has specified using build restorepackages and strongnames etc, and still no luck. 

I've tried following these instructions: http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/ and was able to get the console application working, but haven't been able to get it to work in my web project. 

I'm using an IIS hosted web application. 

The project successfully builds, but when it run's I'm still getting the same NuGet.Core assembly exception as I initially mentioned. I have the NuGet Package Manager (1.6.30117.9648) installed in Visual Studio. 

It's unfortunate, I know it's no ones fault, but I've lost days to try to get this to work. I can't loose any more time to it now, so I am going to have to revert back to the beta and implement a work around for the model binding issues I was initially having. Obviously this is less than ideal as the current working version of the Web API has had some fairly major changes made to it, so my code will be quite different to the final release of the Web API. 

It's a shame there isn't an official update released. 

Thanks again to both of you for your help, I do appreciate it.

Regards,

Glen

Apr 18, 2012 at 2:06 PM

Please vote for following work item, that way we can have a CI build through NuGet.

Cheers,
Christoph

Apr 20, 2012 at 7:12 AM

Just voted for it Christoph, thanks for putting that work item in. 

It would be fantastic if we could get NuGet latest builds!

 

Cheers,
Glen