I got this error message after upgrading my ASP.NET Dynamic Data site to ASP.NET 4.5. The exception was thrown each time an entity with a data annotation referencing a field or filter control was shown. I searched for days to find out what was wrong, including numerous references to replace the ScriptManager control with the ToolkitScriptManager, but that just wasn’t the issue. So, what I finally did was to create a new blank ASP.NET Web Application in Visual Studio 2012. I wanted it somewhat empty, so I could the bits and pieces from the Ajax Control Toolkit sample site, and work out when things went wrong. At first it just didn’t. I had a bare bone application with just the AutoComplete.aspx and the DefaultMaster.master files, as well as the Ajax Control Toolkit installed from NuGet. Worked just fine. Then I started adding the script related bits from my Dynamic Data project, but to no avail. Finally, I went over the Bin folders for a comparison between the two, and after listing the ones that were “extra” in the Dynamic Data project, I double-checked if they were all needed. Turns out the Microsoft.ScriptManager.MSAjax.dll assembly was no longer used by the web application project, so I deleted it. Damned, that did the trick; unbelievable.
I just moved a Visual Studio solution containing a Web Application project from a Windows 7 based dev box to a Windows 8 based dev box, and in line with recommended security guidelines, I try to avoid running Visual Studio (2012 in this case) as an admin. However, in this case, the solution is to run VS as an administrator. Sigh… I do Wonder though as to why VS would need admin access to IIS. I’m sure there is a plausible explanation, but I just don’t see it.
I am working on my Dynamic Data website, or rather web application, in VS 2012 RC, and after reading Dynamic Data Unleashed, http://www.amazon.com/ASP-NET-Dynamic-Data-Unleashed-Oleg/dp/0672335654/ref=sr_1_1?ie=UTF8&qid=1342425509&sr=8-1&keywords=dynamic+data, I picked up a few nice tricks, including how to secure your data at the entity level. So, I copied some of the sample code across to my solution, and once everything was building nicely, I started testing the new bits. First access to an entity worked just fine, but any other attempt to access the same entity or any other entity for that resulted in this error:
System.ArgumentNullException: Value cannot be null. Parameter name: principal
Rather annoying, since the sample code worked just fine. It turns out that the methods for checking if the current user is allowed to read a specific entity received a principal that was null. Here is the signature of one of the methods:
public override bool CanRead(IPrincipal principal)
The method is called from another method that checks if a column should be scaffolded/shown to the current user.
private bool IsScaffoldable(MetaColumn column)
This method was calling the CanRead method passing
HttpContext.Current.User. This works just fine when you use the ASP.NET Development Server when testing inside Visual Studio. However, if you use IIS Express, it does not work; the error described is consistent. So, I tried the full IIS, but the same thing happened.
It turns out that the issue is with the Integrated pipeline mode, which is new to IIS 7 and later. HttpContext.Current isn’t always available, as you can find more evidence of by Bing’ing it. The solution in my case was to use
I was adding filters (grabbed from “Dynamic Data Steve’s” website here, http://csharpbits.notaclue.net/2010/11/five-cool-filters-for-dynamic-data-4.html) to my Dynamic Data website and the Autocomplete filter makes use of the AJAX Control Toolkit, http://ajaxcontroltoolkit.codeplex.com/. Steve has done a fantastic job over the years with customizing many aspects of Dynamic Data, so I was a little sad to see that I got this error Invalid Animation definition for TargetControlID=”…”: The ‘Animations’ start tag on line x position x does not match the end tag of ‘OnHide’. Line x, position x., when trying to view a table/entity in the ListDetails view. After quite a thorough investigation, it turned out it was because of the presence of the VisualStudioDesignTime key you can add to your appSettings element in web.config.
VisualStudioDesignTime:Enabled" value="true" />
It is used by the new Page Inspector, which you can find information about here, http://blogs.msdn.com/b/webdevtools/archive/2011/09/22/page-inspector-for-visual-studio-11-developer-preview.aspx. Remove the add element/tag and the error goes away.
After updating to Visual Studio 2012 RC, I now get the error whether or not the VisualStudioDesignTime:Enabled key is present or not. However, if I remove the 4 comments within the opening and closing ajaxToolkit:AutoCompleteExtender tags, everything works just fine, even with the VisualStudioDesignTime:Enabled key present. 🙂
When creating a new WebForm in ASP.NET by using Visual Studio 11, I noticed that a context menu is displayed, once you type in the = (equal sign) after the event name in Source view. It is this context menu that contains the item Create New Event. If you then press Tab, the event handler method is automatically generated in the code-behind file. I like it, after having used with XAML and particularly Silverlight development. 🙂
I was working on a Dynamic Data website and everything was working great. Then I decided to add some of the features from a standard ASP.NET Web Application project, including the CSS and Login functionality to the Dynamic Data project. This worked well too. Then I reworked the routing to use the ListDetails.aspx view only, and after a while I started getting this error, No key property values were found during an update or delete operation. Check to ensure that key properties specified as binding expressions are available to the data source., but only for some tables. Obviously, the first thing to check was the Entity Framework model, to see what those tables had in common and what they didn’t have in common with the other tables. I just could not find anything there. I got the error when doing an inline update in the GridView on the ListDetails view, not if I used the FormView for updating, so I scrapped the idea of the data model being at fault. I then also found that the Select functionality in the Gridview control did not update the FormView control with the selected row, which it did previously. Now I was on to something; the view state had been turned off on the ContentPlaceHolder control in the master page. I’m not entirely sure how this caused the error, but once it was turned back on, everything worked as expected.
When using the Generate Local Resource functionality (available from the Tools menu) in Visual Studio 11 Beta, it only works for a single Web Form. For subsequent Web Forms, the menu item is grayed out in Design mode and missing in Source mode. This seems to be a Beta error, as you can close and reopen Visual Studio 11, and regain the functionality. A little trivial, but it works. 🙂
I am developing a data entry application in Visual Studio 11 Beta, by using the ASP.NET Dynamic Data Entities Web Application project template. I decided to add the ASP.NET Menu control to the Site.master master page, but then I started getting this error, The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).
While the error more or less tells you where things go wrong, the stack trace looks like this:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).]
System.Web.UI.ControlCollection.Add(Control child) +9719987
System.Web.UI.WebControls.MenuRendererStandards.PreRender(Boolean registerScript) +89
System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +238
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Okay, so the rendering isn’t quite working. I did a quick search for this error and found that a lot of developers have had this issue over the years, so definitely nothing to do with the .NET Framework 4.5 or VS11 Beta. What fixed the issue was to move the script element,
<script src="<%: ResolveUrl("~/Scripts/modernizr-2.0.6-development-only.js") %>"></script> out of the head element and into the body element. Very simple fix…