.NET Framework

Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. Access is denied.

Problem: Recently i came across this problem while switching to a new Windows 7 64 bit m/c. The web site at hand was working fine on my previous m/c Windows 7 64 bit RC1. The error and the event log were basically not very helpful either.

Resolution:

So here is what I did to fix the issue (to get it to work using IIS):

1. Make sure that the dll in question is either set to “Copy to: Local). Go to References, right click on AjaxControlToolkit and select properties. In my case it was already set to Copy Local. So that was not the issue

2. Open IIS Manager, browse to the AppPool (in my case it was the DefaultAppPool… it is just a Dev box, ok!). Go to Advanced Settings, and set Enable 32-bit Applications to true. Now that did fix the problem I was having.

For Cassini:

1. I had to give modify rights on the asp.net temp folder  to the Apppool identity (in my case IIS users group).

Discussion

  • On further research (i.e. “google”), I came to the conclusion that it was a permissions error related to the Temporary ASP.NET Files folder (C:\Windows\Microsoft.NET\Framework64\v2.0.50727). Some of the other fixes for this problem can be found on other blogs. They relate to the access permissions on the ASP.NET folder, Trust level Settings on the Website, and Anti-virus settings. Here is a link to some of them:
  • What I found was that the main focus while resolving this error should be on the later part of the error that says ‘Access is denied’ or “Invalid Argument’ etc.. that will help you in attacking the issue. In my case it was the fact that I was running a 32 bit app on a 64 bit mc and a permissions issue as well on the Temporary ASP.NET folder.
  • If you get an ‘Access Denied’..try checking the permissions on the Temp ASP.NET folder.
  • If you get ‘Invalid Argument’ try cleaning the temp asp.net folder and restarting the web site.

http://lichao.net/eblog/fix-access-is-denied-exception-from-hresult-0×80070005-e_accessdenied-on-local-machines-200905307.html

http://weblogs.asp.net/joshuajohnson/archive/2008/12/22/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0-215-80070057-e-invalidarg.aspx

http://msforums.ph/forums/t/46678.aspx

.NET Framework
General

Comments (1)

Permalink

RESTFul Services in Silverlight - CT Code Camp June 2009

Downloade the Presentation and Code 

The Connecticut User Group organized a full day code camp event in Bloomfield, CT. The topic I presented on was “RESTFul Services and Silverlight”. The presentation was organized around the following main topics:

  • Web Services via SOAP
  • RESTFul Services
  • Creating a WCF RESTFul Service
  • Consuming a Custom WCF RESTFul Service in Silverlight

The attached slide deck will provide you with highlights on each topic. The code samples revolve around the AdventureWorks Database. I have partitioned the code into Data Access, Service Layer and a UI Layer.

  • Database: AdventureWorksDB from code plex. You can download it from here: http://www.codeplex.com/MSFTDBProdSamples
  • Data Access: Used Nettiers and Codesmith to Generate the CRUD methods to access Adventure Works.
  • Service Layer: WCF, ASMX and WCF REST service examples. I have also included a sample service from John Papa’s Data Services with Silverlight book. I would recommend this book for who ever is working with Siverlight
  • UI Layer: Consists of a ASP.NET web site that houses the silverlight controls and the silverlight controls themselves. The services are conusmed by silverlight.

During the actual presentation, i also created a simple WCF Service and demo’ed how to use a simple SOAP WCF service in a silverlight client using the Asynchronous pattern.

Check the samples out!

Happy coding

Reddy (reddy.kadasani@tallan.com)

.NET Framework
Presentations
User Groups
WCF

Comments (0)

Permalink

Content from LINQ Code Camp Presentation (6/13/09)

On June 13, 2009 I was privileged to give a presentation at the Hartford Code Camp at New Foundations in Bloomfield, CT.   The event was a great success, with 29 presenters,  35 sessions, and more than 150 people in attendance.  I’d like to say thank you to anyone who was able to attend my session on LINQ, my group was great and had a lot of insightful and pointed questions.

As promised, I’m posting the content from the presentation including the PowerPoint files and Demo Code.

If anyone has any questions about the content, please feel free to e-mail me at mgerety@tallan.com

Presentation and Content Files: LINQ Presentation And Files

.NET Framework
Presentations

Comments (0)

Permalink

Convert Multi-page image to Collection of Bitmaps

Recently on a project, we had the need to convert a saved multi-page tiff to a collection of bitmaps for viewing in a UI using standard GDI+ methods. These bitmaps also needed to be printed in a high quality way for submission to a government agency.  This method ensures that no quality will be lost from the creation of the new bitmap objects.

/////////////////////////////////////////
// by Craig Vallee
// Consultant
// Tallan, Inc.
/////////////////////////////////////////

private static List<Bitmap> ImageToBitmap()
{
    //Create and Image object from file path and name
    Image originalImage = Image.FromFile(@"C:\Temp\Your_File.tif");

    //Create a collection of Bitmap objects 
    List<Bitmap> bitmapList = new List<Bitmap>();

    //Place holders for setting resolution of new Bitmap objects
    var xResolution = originalImage.HorizontalResolution;
    var yResolution = originalImage.VerticalResolution;

    //Create FrameDimesion for iteration through file frames
    FrameDimension frameDimension = new FrameDimension(originalImage.FrameDimensionsList[0]);

    //Framecount of image for iteration through file frames
    int frameCount = originalImage.GetFrameCount(FrameDimension.Page);

    //Simple iteration through file frames
    for (int i = 0; i < frameCount; ++i)
    {
        //Create bitmap to hold individual frame
        Bitmap bmp;

        //Moves active frame pointer to next frame in iteration
        originalImage.SelectActiveFrame(frameDimension, i);

        //Cast image frame to Bitamp holder
        bmp = (Bitmap)originalImage;

        //Create new Bitmap from placeholder
        Bitmap temp = new Bitmap(bmp);

        //Set bitmap resolution based on original resolution
        temp.SetResolution(xResolution, yResolution);

        //Add Bitmap to Bitmap collection
        bitmapList.Add(temp);
    }
    return bitmapList;

}

-Craig

.NET Framework
General

Comments (0)

Permalink

Windows Worfklow: Error 1342 Activity X validation failed: Can not find the condition Y

This is just a small tip for anyone doing any WWF work:  The workflow’s name property MUST MATCH file workflow filename or rules and conditions will not be found, and the workflow will not be instantiated.

Example:

Create a sequential workflow.  Call it WorkflowA.cs.

Click the workflow in the designer mode, and change the name of the workflow in the property window to WkflwA.  Add any activity that takes conditions (i.e., if/then/else). 

Add a valid condition to this activity.

Attempt to start the workflow.

 

You will get a WorkflowValidationFailedException saying that the Workflow failed validation.  To correct this issue, rename the workflow back to “WorkflowA” and restart.  The workflow will instantiate without issue.

.NET Framework
General

Comments (0)

Permalink

Creating a Project Installer for a Windows Service

I recently had to create a Windows Service for a project I’m currently working on.  Rather than installing/uninstalling using InstallUtil, I decided to create a project installer to do the work for me.  It took a little bit of digging to gather all of the necessary steps, so here is what I did to get up and running.

  1. Create your Windows Service project and Windows Service.
  2. Navigate to the designer for your Windows Service. Under the properties for your service you should see (Name) and ServiceName. Fill in both of these properties with your desired names. You will need to reference these later.
  3. In the designer for your Windows Service, right-click and click Add Installer. You should now have a ProjectInstaller.cs file, along with a designer file for the installer.
  4. Navigate to the designer for your new project installer. You should see two components, a Service Process Installer and a Service Installer. Under the Service Installer properties, you will need to add a DisplayName, and provide the ServiceName of the service you will be installing. The ServiceName must match the (Name) property of the service.
  5. Build your Windows Service project. Now in the same solution, add a new Setup Project. This will provide the Wizard interface for the installation process.
  6. After adding the project, you need to add the primary output of your Windows Service to the Setup Project. Do this by right-clicking on the Setup Project -> Add -> Project Output. Select your Windows Service project from the drop down, highlight Primary Output and click OK.
  7. Up to this point the installer will install the correct files, but it doesn’t know what to do with the files. We can add custom actions to do the service installation work. Right-click on the Setup Project -> View -> Custom Actions. For a Windows Service we need to add actions for Install, Rollback, and Uninstall. Right-click each of these and click Add Action. Double click Application Folder and select the Primary Output from your Windows Service project.
  8. You can now build your Setup Project. The output of this build will be two setup files which are used to install your new Windows Service.

-Jon

.NET Framework
General

Comments (0)

Permalink

Writing ASP.NET MVC Applications on MacOS X?

Interesting news today, there’s a new build of MonoDevelop that works with MacOS X.  MonoDevelop is a fully functional IDE for writing apps in Mono, a cross platform .NET library.

 

image

 

Follow the link for more info: http://tirania.org/blog/archive/2009/May-05-1.html

.NET Framework
Mono

Comments (0)

Permalink

Recover from a WCF Service Fault, Part 2 (Generic ServiceClientFactory Class)

After finding the simple solution for handling WCF Service Faults in the original post, I figured it should be relatively trivial to find a generic solution to this problem if you’re using similar WCF clients in a project and want to reset ALL of them on a channel fault.  I developed a generic ServiceClientFactory class that will generate a WCF Service Client instance from a generic “GetClient” function and will automatically handle resetting of faulted channels.

Class Implementation Source Code:

/* Service Client Factory
 * Author: Michael Gerety, Senior Consultant, Tallan, Inc.
 * Description: A generic service client factory that automatically
 *              resets faulted channels for WCF services that have
 *              endpoints and behaviors defined in web/app.config files.
 */             

using System;
using System.Collections.Generic;
using System.ServiceModel;
namespace Tallan
{
    /// <summary>
    /// Singleton factory class for WCF Services.
    /// Creates service clients based on interface type and automatically
    /// resets faulted channels.
    /// </summary>
    public class ServiceClientFactory
    {
        private readonly Dictionary<Type, object> factories;
        private static ServiceClientFactory instance;

        private ServiceClientFactory()
        {
            factories = new Dictionary<Type, object>();
        }

        /// <summary>
        /// Retrieves a service client for the interface specified in generic parameter.
        /// </summary>
        /// <typeparam name="T">Interface type to use for Service Client creation.</typeparam>
        /// <returns>Service client instance for specified interface.</returns>
        public T GetClient<T>()
        {
            var genericType = typeof(T);
            Type serviceClientType;
            if (genericType.IsInterface)
            {
                serviceClientType = GetClientType(genericType);

                if (serviceClientType == null)
                    return default(T);

                var client = Activator.CreateInstance(serviceClientType);
                if (!(client is ICommunicationObject))
                {
                    client = null;
                    return (T)client;

                }
                (client as ICommunicationObject).Faulted += Channel_Faulted<T>;

                if (!factories.ContainsKey(typeof(T)))
                {
                    var prop = serviceClientType.GetProperty("ChannelFactory");
                    var factory = prop.GetValue(client, null);
                    factories.Add(typeof(T), factory);
                }
                return (T)client;
            }
            return default(T);
        }

        #region Reflection Utilities
        private static Type GetClientType(Type type)
        {
            var assy = type.Assembly;
            var serviceModelAssy = typeof(ChannelFactory).Assembly;
            var clientBaseType = serviceModelAssy.GetType("System.ServiceModel.ClientBase`1").MakeGenericType(type);

            foreach (var classType in assy.GetTypes())
            {
                if (classType.IsClass && type.IsAssignableFrom(classType))
                {
                    if (classType.IsSubclassOf(clientBaseType))
                        return classType;
                }
            }

            return null;
        }

        #endregion

        /// <summary>
        /// Event handler for ClientBase.Faulted event.
        /// </summary>
        /// <typeparam name="T">Interface type of service</typeparam>
        /// <param name="sender">ClientBase instance</param>
        /// <param name="e">Event Args</param>
        private void Channel_Faulted<T>(object sender, EventArgs e)
        {
            ((ICommunicationObject)sender).Abort();
            var factory = (ChannelFactory<T>)factories[typeof(T)];
            factory.CreateChannel();
        }

        /// <summary>
        /// Returns the singleton instance of ServiceClientFactory.
        /// </summary>
        /// <returns>Singleton instance of ServiceClientFactory</returns>
        public static ServiceClientFactory GetFactory()
        {
            if (instance == null)
            {
                instance = new ServiceClientFactory();
            }
            return instance;
        }
    }
}

Sample Usage:

//Get instance of ServiceClientFactory
            var factory = ServiceClientFactory.GetFactory();
            var client = factory.GetClient<IAuthenticateService>();
            try
            {
                client.AuthenticateUser("joe", "bob");
            }
            catch (Exception)
            {
                //Handle Exception
            }

            //channel isn't in faulted state, you can re-execute.
            client.AuthenticateUser("joe", "bob1");

This was thrown together and proven to work for my purposes.  If anyone has any suggestions about how to improve this utility class, please feel free to comment or contact me with suggestions.

.NET Framework
WCF

Comments (2)

Permalink

Unable to launch the ASP.NET Development Server because port ‘n’ is in use.

This error displays itself when trying to debug a Web Application or Web Service project from within Visual Studio 2005 and/or Visual Studio 2008 on machines running ESET NOD32 Antivirus.  This problem seems to occur every couple of months on our team, and for some reason we always go round and round trying to troubleshoot it, even though we’ve seen the fix numerous times, so I’m documenting it here again.

Step 1:

image

Double-click the NOD32 Antivirus link in your system tray.  Highlight “Setup” in the left pane and click “Antivirus and antispyware”

 

Step 2:

Click ConfigureU under Web access protection (see image above).

Step 3:

image

Select “Antivirus and antispyware” –gt; “Web access protection” –gt; “HTTP” –gt; “Web Browsers”  Find all of your devenv.exe instances in the list and click the check box next to them until a red x appears (image ).  Note: DO NOT make the box checked (image ) or the issue will continue!

Step 4:

Click “OK” and close NOD32.  You should now be able to launch the ASP.NET Development web server again without issue.

.NET Framework
General

Comments (0)

Permalink

Debugging Windows Services in the Visual Studio IDE

In one of our current projects we made  the decision to move our WCF services from an IIS hosted environment into a Window Service hosted environment.  This move gave us greater flexibility in mangement and distribution of our WCF services, and allowed us to use multiple endpoints (http, net.tcp, pipes) without the need for Windows Activation Services (WAS) which would have required that our clients be running Vista and/or Server 2008.

One of the major pains about working with developing Windows Services, however, is that you can’t start a windows service project from within the debugger.  You have to instead install and start the service to execute it.

I have a workaround for this that allows us to test our WCF services from within the IDE without installing the service.

Steps:

1. In the Windows Service, put any code you’d normally put in the OnStart and OnStop events into their own functions:

private void OpenWCFServices()
{
    householdHost.Open();
}

private void CloseWCFServices()
{
    householdHost.Close();

}
protected override void OnStart(string[] args)
{
    OpenWCFServices();
}

protected override void OnStop()
{
    CloseWCFServices();
}

2. Using precompiler directives, specify 2 public functions that also call your start and stop methods.  This allows these methods to be publicly available at debug time only (you’ll see why in Step 3).

#if DEBUG
        public void DebugStart()
        {
            OpenWCFServices();
        }

        public void DebugStop()
        {
            CloseWCFServices();
        }
#endif

3. Create a new Windows Form in your service project.  Alter the constructor so that it requires an instance of your service to be created.  Add a Button to stop your WCF services to the form.

    public partial class DebugForm : Form
    {
        private FEEAApplicationServiceHost service;
        public DebugForm(FEEAApplicationServiceHost service)
        {
            InitializeComponent();
            this.service = service;
            this.service.DebugStart();
        }

        private void ExitButton_Click(object sender, EventArgs e)
        {
#if DEBUG
            service.DebugStop();
#endif
        }
    }

 

4. Alter your Program.cs to use this form as your running application instead of the Service using the same #if DEBUG directives.

       /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {

#if DEBUG
            Application.EnableVisualStyles();
            Application.Run(new DebugForm(new FEEAApplicationServiceHost()));
#else
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new FEEAApplicationServiceHost()
            };
            ServiceBase.Run(ServicesToRun);
#endif

        }
    }

This allows you to launch your service from the IDE and debug during development, while still having the ability to compile and distribute your service without changing a line of code.  (Although I’d probably recommend removing this code from anything that is truly production-level.

So now, when you right click your service project and select Debug –gt; Start new instance, you see the following form:

 

image

Once this is up, you can start an instance of your code that accesses the service, and you’re all set.

.NET Framework
WCF

Comments (0)

Permalink