Archive for category .NET

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly …

This error usually happens if .NET 4.0 is recently installed or followed by enabling .NET 3.0/3.5 WCF.

Follow these instructions to fix the problem:

  • Open Command Prompt and browse to the following path depending on the version of Operating System you have.

    • 32-bit: %windir%\Microsoft.NET\Framework\v4.0.30319
    • 64-bit: %windir%\Microsoft.NET\Framework64\v4.0.30319
    If you are using Windows 7 or Server 2008 then you must open the command prompt as Administrator.

  • Run aspnet_regiis.exe /iru

  • Test and make sure .NET 4.0 is enabled in the IIS configurations.

No Comments

SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission

http://blogs.msdn.com/b/narahari/archive/2010/06/03/system-security-securityexception-request-for-the-permission-of-type-system-web-aspnethostingpermission-system-version-2-0-0-0-culture-neutral-publickeytoken-b77a5c561934e089-failed.aspx

SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.]

Platform: Windows Server 2008 R2

This is the most common error you would get when you host your content on a UNC share. http://support.microsoft.com/?id=320268 describes the problem, resolution. However in this specific case content is not hosted on UNC share.

Cause:

This issue would happen when you download a file from Internet or Network Location, etc. Windows now preserves the zone information for file(s). This identifies where the file came from and displays appropriate warning messages, indicating you to be careful.

Note: Also when you copy the zip file from network location /Internet and extract the same, all the files contained in the zip file also will get this attribute set.

Resolution:

You can resolve this issue by following any of the following methods.

Method#1 Go to the properties of precompiled dll’s, check to see if it has following security message (at the bottom of the window): “This file came from another computer and might be blocked to help protect this computer.” If present, click “Unblock”, “Apply” and “OK”.

If you have multiple dlls in your application, you would need to perform this step to all dlls one by one.

Method#2 Run the below caspol command to resolve the issue Drive:WINDOWSMicrosoft.NETFrameworkv2.0.50727caspol.exe -m -ag 1 -url “file:////c:mysitecontent*” FullTrust -exclusive on

Note: Please substitute “c:mysitecontent*” with actual path where ASP.net pre compiled dlls are located.

Alternatively, you can use below methods to get around the issue.

To avoid the “This file came from another computer and might be blocked to help protect this computer.” You can use one of the following methods depending on your scenario.

1) Move all the files to non NTFS partition i.e. FAT and move them back to NTFS partition. When you move the files to non NTFS partition, it will not maintain zone information.

2) Use the “Strems v 1.56” tool to remove streams

a. Download “Streams v1.56” from http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx

b. Execute the following command from command line:

“streams -s -d directory”

3) If you have copied a zip file to your machine that has the above attribute, before you extract, just unblock the zip file( as mentioned in resolution section) and then proceed with extraction.

4) There is a Group Policy, that you can Enable to make sure zone information is not preserved.

a. Run gpedit.msc ( From Run Prompt or CMD prompt)

b. Navigate to Local Security Policy > User Configuration > Administrative Templates >Windows Components >Attachment Manager

c. Enable “Do not preserve zone information in file attachments” setting.

This will only make sure that zone information is not present for the files that you copy after the policy is enabled. For Existing files, you would still need to use one of the above methods. Also, please consult with your Administrator, Team before you enable this setting, as this might be needed for other applications and might break those, if you enable it without taking consent from Administrator(s)/your team.

No Comments

AspNetHostingPermission Security Exception

I had this issue with Windows Server 2008 R2 with IIS 7 on a .NET 2.0 Integrated Application Pool and it drove me insane for hours. I finally found the solution at the following link:

System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

http://dbvt.com/blog/post/AspNetHostingPermission-Security-Exception-Fix-with-Ajax-in-IIS7.aspx

Solution is to go to the Advanced Settings for the Application Pool and make sure the “Load User Profile” is set to True.

No Comments

WPF

I’ve been looking at WPF and how we can utilize it in our applications so I’ve compiled a list of items that convinced me to start working with it.

WPF vs Window Forms
http://windowsclient.net/wpf/white-papers/when-to-adopt-wpf.aspx

Why should you start using WPF?
http://stackoverflow.com/questions/636028/advantage-of-wpf-app-vs-winform-for-business-apps

What should you use WPF for?
http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/

First off, WPF is not just for applications which simply require “eye candy.” That is the most common and frustrating misperception about WPF which I’ve encountered. Sure, WPF has a lot of support for flashy visuals and animations. But that’s not all it’s good for. If you’ve worked with WPF for any substantial period of time you are probably well aware of this fact, so I won’t keep harping on the issue.

WPF is an especially great platform to use if your applications involve various media types. For example, if you need to incorporate video, or documents, or 3D content, or animated transitions between a sequence of images, or a combination of any of the above. WPF is also great if you need to create a skinned user interface, or if you need to bind to XML data, or dynamically load portions of a user interface from a Web service, or want to create a desktop application with a Web-like navigation style.

Another great reason to use WPF is if you have a team of developers who are bored with WinForms and are itching to get into something new and cool. Of course this is not as powerful and compelling a reason from a business perspective, but nothing promotes employee retention better than keeping the employees interested in their jobs.

WPF Cheat Sheet
http://www.nbdtech.com/Free/WpfBinding.pdf

No Comments