SecurityException / IIS .Net Trust Levels / Diagnostic Traces

This dasBlog website is now being hosted at WinHost.  In reality, the migration was trivial.  Using IIS Manager, there is an option under Deploy to “Export Application…”which saves the entire site to a .zip file.  And then after connecting to the new site, one simply runs “Import Application…” and points to the saved .zip file—simple and easy.  Except that when navigating to the new site, one is greeted with an unfriendly:

Server Error in ‘/’ Application.

 


 

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

Source Error:

 

[No relevant source lines]

plus the detailed call stack…

The quick and dirty fix was to change the .Net Trust Level from High to Internal.

image_2

image_4

 

image_6

However, this just didn’t feel safe and after doing some searching on the web I found this great post on Useless Inc.  It appears that something in the process modified the web.config to add diagnostic tracing for OpenID. Just as Tomer Gabel did, I removed this section from the web.config

<!--  
  <system.diagnostics>
    <assert assertuienabled="false"/>
    <switches>
      <add name="OpenID" value="4"/>
    </switches>
    <trace autoflush="true" indentsize="4">
      <listeners>
        <add name="fileLogger" type="System.Diagnostics.TextWriterTraceListener"
             initializeData="openidConsumerTrace.txt" traceOutputOptions="None"/>
      </listeners>
    </trace>
  </system.diagnostics>
-->

and set the trace to false:

  <trace enabled=falsewriteToDiagnosticsTrace=truerequestLimit=1000pageOutput=falsetraceMode=SortByTimelocalOnly=false/>

and now this site is happily running…

Extension methods in C#

Wikipedia has a very good overview of extension methods in C# here.

Basically, if you create a static method in a static class and the first parameter includes the keyword ‘this’ then the first parameter will be the calling object and you’ve created an extension method.

Here is a quick example console application (based on the example from Wikipedia):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("abcdefg".ExtReverse());
            Console.ReadLine();
        }
    }

    public static class ExampleExtension
    {
        public static string ExtReverse(this string input)
        {
            char[] chars = input.ToCharArray();
            Array.Reverse(chars);
            return new String(chars);
        }
    }
}

Uppercase vs. UpperCase

XamlParseException occurred:

The property ‘VerticalGridlinesBrush’ was not found in type ‘System.Windows.Controls.DataGrid’. [Line: 19 Position: 30]

Took me 30 minutes to see that

<Setter Property="VerticalGridlinesBrush">
    <Setter.Value>
        <SolidColorBrush Color="#FFACACAC"/>
    </Setter.Value>
</Setter>

should be

<Setter Property="VerticalGridLinesBrush">
    <Setter.Value>
        <SolidColorBrush Color="#FFACACAC"/>
    </Setter.Value>
</Setter>

Next time I need to hit ctrl+space sooner…

devenv.exe.config

While trying to compile a demo Silverlight application, I ran into this build error:

System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

The link above provided by Visual Studio is only marginally helpful.  Luckily there is stack overflow which had this question/answer: http://stackoverflow.com/questions/1823339/error-building-visual-studio-2010-silverlight-4-projects-on-windows-7-with-xp-mod

The location of my devenv.exe.config is C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

Sometimes I think Microsoft went overboard with safe computing.

Samsung Focus Windows Phone 7 (WP7) using AT&T

My Samsung Focus came in the mail today to replace the old iPhone 3G I was trying to use.  I say trying because with each OS release my old iPhone would get slower and slower.  While the iPhone 4 looks like an improvement over the 3G (click here for the apple comparison), I like the idea of using Silverlight and XNA for phone development.

While I love the phone and WP7, getting it working had some hiccups.  First upgrading from the iPhone to the Focus wiped my voice mails and I had to call AT&T support to setup voicemail.  That said, the AT&T service was very good.  Next, I found it impossible to change the Xbox live account without doing a factory reset.  It took the first Live account I used and made that the default, and there appears to be no way to set a different account as an Xbox live default.  After that, I managed get into a state where the Zune music player would not launch (turning the phone on/off fixed that).  And finally, the first application I tried to buy gave me a strange error code; yet, when I tried again a few hours later, everything work.

And yes, despite these snafu’s  the phone is great.  Why?  I’ll save that for another post.

In the mean time, for a good comparison of WP7 devices, check out ElektricForest’s chart.

Installing the latest Zune 4.0 Software on Windows Server 2008

Step 1: Download the latest Zune software from http://www.zune.net/en-US/products/software/download/default.htm (which should be the single file ZuneSetupPkg.exe).

If you just run ZuneSetupPkg.exe you will get this lovely message:

image_2

I can only assume Windows Server 2008 is not supported to save on QA time yet the software is running fine for me.

Step 2: Start-up a cmd.exe prompt with Administrator rights.image_4

Step 3: Navigate to the downloaded package and extract all the files it contains by typing ZuneSetupPkg.exe /x

image_6

which will ask for a destination directory

 

Step 4: CD to the x64 folder (I have to assume if you are running Windows Server 2008 you are using the 64 bit version) and then the packages folder.image_8

Your command prompt should look similar to

image_15

 

Step 5: Install the zune-x64.msi using msiexec.  Type: msiexec /i zune-x64.msi

image_10

 

Step 6: Run the Zune.exe software from the start menu and enjoy.

IMHO, the Zune software is MUCH better than iTunes!  I wish I had switched sooner (and I might have if it was easier to install).