14 June 2008

Resolving Asp.Net EventID 1334

If you are seeing Event ID 1334, with a similar message:

Failed to initialize the AppDomain:/LM/W3SVC/99999999/Root

Exception:
System.IO.FileLoadException

Message: Could not load file or assembly
'System.Web, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
Access is
denied.
StackTrace: at
System.Reflection.Assembly._nLoad(AssemblyName
fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean
forIntrospection)
at
System.Reflection.Assembly.nLoad(AssemblyName
fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint,
StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean
forIntrospection)
at
System.Reflection.Assembly.InternalLoad(AssemblyName
assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark,
Boolean forIntrospection)
at
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection)
at
System.Activator.CreateInstance(String assemblyName,
String typeName, Boolean
ignoreCase, BindingFlags bindingAttr, Binder
binder, Object[] args, CultureInfo
culture, Object[] activationAttributes,
Evidence securityInfo,
StackCrawlMark& stackMark)
at
System.Activator.CreateInstance(String
assemblyName, String typeName)
at
System.AppDomain.CreateInstance(String
assemblyName, String typeName)
at
System.AppDomain.CreateInstance(String
assemblyName, String typeName)
at
System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String
appId, IApplicationHost appHost, HostingEnvironmentParameters
hostingParameters)
at
System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String
appId, IApplicationHost appHost, HostingEnvironmentParameters
hostingParameters)

Make sure that you have added the proper accounts with File System permissions to your web folder. On Windows 2003 with IIS6, these should be (for a default setup): Network Services (Make sure it is Network Services and not just Network), ASPNET, IUSR_ and IWAM_.

13 June 2008

Asp.Net - Add Attributes to RadioButtons (Finally)

This was shockingly simple in VS2008 targeting .Net 3.5, compared to how shockingly complicated it used to be.

Dim oRad As New RadioButton
oRad.InputAttributes.Add("myattribute", "myattributevalue")

Does it get any easier than that???

28 April 2008

Protect Your Scalar Functions in Strongly-Typed DataSets

How many times have you created a modified insert statement in a strongly-typed dataset that returns the new primary key value of the inserted record using, for example:

INSERT INTO [table] (col) VALUES (@col);
SELECT SCOPE_IDENTITY();


After you create the query, you mark the execute mode as scalar so that you can get the value back out, only to find the next time you modify that table adapter, the query loses its execute mode and reverts back to Non-Query (the default execute mode for Insert queries). All of the sudden your post-insert logic is doing all sorts of baffling things related to the first record in the table, or worse, no record.

It seems that Visual Studio is supposed to mark the query when you modify it so that future updates don't overwrite your customizations, but unless I am absolutely stupid, this never works.

Thwart the behavior by doing something so illogical that it must work.
When using the Add Query wizard on the table adapter
  1. Select "Use SQL statements", click Next.
  2. Select the Insert option (if you want to get a base insert statement for your self, copy the query into your clipboard, go previous and change your query type to "SELECT which returns a single value")
    - OR -
    Select the "SELECT which returns a single value" (if you have your query and don't mind typing it)
    and of course, click Next.
  3. Enter your query, click Next.
  4. Name your query, click Next.
  5. Oh! the horror. The wizard is throwing a warning message: Failed to get schema for this query. Should we halt, go back, rack our brains for hours trying to determine the best course of action to resolve this tragic error? Of course not. If you are reasonably certain that the query you just pasted or typed into the field is correct, apply your settings and click Finish. You will be rewarded with what should be a table adapter update-proof insert statement that NEVER loses its scalar execution mode. NEVER!

25 April 2008

For Frequent Hosts File Updaters

If you find yourself constantly modifying your hosts file, and are always irritated about the incessant need to choose the program to edit the file with, try this:

  1. Create a short-cut to your hosts file on your desktop (or wherever).

  2. Right click the hosts file and select properties.

  3. Change the target to something like:

    notepad c:\windows\system32\drivers\etc\hosts

    or, in my case, since editplus is the best text editor ever:

    "C:\Program Files\EditPlus 3\editplus.exe" c:\windows\system32\drivers\etc\hosts

  4. Click OK.

That's it. You're done. Now whenever you want to make a change, just click your shortcut and the hosts file will magically open, ready for editing.