Saturday, March 5, 2011

Ambiguous reference - The type or namespace name 'Quartz' could not be found (are you missing a using directive or an assembly reference?)

Problem:
Environment: VS 2010 .Net 4.0 Console app using Quartz.Net http://quartznet.sourceforge.net/ as a Project Reference.

I would get an Ambiguous reference listing Quartz.IJob twice.

I had only 1 reference to Quarts in the list of References for my Project, that showed up as Quartz.2008.

Compile errors:
Error    1          The type or namespace name 'Quartz' could not be found (are you missing a using directive or an assembly reference?)
Error    5          The type or namespace name 'JobExecutionContext' could not be found (are you missing a using directive or an assembly reference?)  

Quartz Project properties had the target framework set to .NET Framework 3.5.

Solution:
Change the Target framework on the Quartz.2008 project properties to .NET Framework 4.  I ensured my project used .NET Framework 4, also.

If you get the following error in Quartz, then you had set the Target framework to .NET Framework Client Profile instead of .NET Framework 4.

Error    6          The type or namespace name 'HttpContext' could not be found (are you missing a using directive or an assembly reference?)          xxxx\Quartz.NET-1.0.3\src\Quartz\Util\LogicalThreadContext.cs    41        4            Quartz.2008




Failed to start monitoring changes to 'path' because access is denied.

Problem:
Brought up a web page and was presented with this error:

Server Error in '/' Application.


Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 
 
[HttpException (0x80070005): Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.]
   System.Web.DirectoryMonitor.AddFileMonitor(String file) +8805891
   System.Web.DirectoryMonitor.StartMonitoringFileWithAssert(String file, FileChangeEventHandler callback, String alias) +94
   System.Web.FileChangesMonitor.StartMonitoringFile(String alias, FileChangeEventHandler callback) +340
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate2(StandardDiskBuildResultCache diskCache) +790
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(StandardDiskBuildResultCache diskCache) +55
   System.Web.Compilation.BuildManager.RegularAppRuntimeModeInitialize() +174
   System.Web.Compilation.BuildManager.Initialize() +261
   System.Web.Compilation.BuildManager.InitializeBuildManager() +246
   System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +350
 
[HttpException (0x80004005): Failed to start monitoring changes to 'C:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\root\b6230deb\7677a327\hash\hash.web' because access is denied.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8950644
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


Solution:
First, I had to close Visual Studio 2010, then I deleted c:\Users\xxxx\AppData\ocal\Temp\Temporary ASP.NET Files.
Reopened Visual Studio and ran it again in debug mode, worked fine.

Monday, February 28, 2011

MVC3 - Server Error in '/' Application. The resource cannot be found.



Problem:
MVC3 – You added your HttpPost method in your Controller, and you get:

Server Error in '/' Application.


The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Movies/Edit/1

Code:
        [HttpPost]
        public ActionResult Edit(Movie model)
        {
            try
            {
                var movie = db.Movies.Find(model.ID);

                UpdateModel(movie);
                db.SaveChanges();
                return RedirectToAction("Details", new {id=model.ID});
            }
            catch (Exception)
            {

                ModelState.AddModelError("", "Edit Failure, see inner exception");
            }

            return View(model);
        }



Solution:
You forgot to add the Get method to the Controller class:
Code:
        public ActionResult Edit(int id)
        {
            var movie = db.Movies.Find(id);
            if (movie == null)
                RedirectToAction("Index");
           
            return View(movie);
        }