DCSIMG
May 2010 - Posts - Janiv Ratson's Blog

Janiv Ratson's Blog

.NET (especially WPF) and Technologies issues I have time to cover

על הבלוג

These postings are provided "AS IS" with no warranties, and confer no rights.

Janiv LinkedIn Profile

Locations of visitors to this page

My Blog Barcode

Interesting Blogs

May 2010 - Posts

.NET Framework Targeting Error (.NET Framework Client Profile)

Two of my colleagues: Alon Nativ and Ziv Farjun have found an interesting, yet confusing, issue in Visual Studio 2010 and .NET Framework 4.

They work on a .NET Framework 4 solution which includes few .NET Framework 4 projects. To test the project they created a Console Application project, added a reference to their other projects, used the appropriate namespace, and created a class that is defined in one of their projects. Everything is made by the (old) book. However, the project failed to build.

The error they got was: The type or namespace name "name" does not exist in the namespace "namespace". (Are you missing an assembly reference?)

The problem occurred because the new Console Application targeted the.NET Framework 4 Client Profile (which is the default for this project template) while the other projects targeted the full .NET Framework version 4.

.NET Framework Client Profile

The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications and it enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.

Applications that target the .NET Framework 4 Client Profile typically improve the deployment experience by having smaller download sizes and quicker install times. An application that targets the .NET Framework 4 Client Profile has a smaller redistribution package that installs the minimum set of client assemblies on the user's computer, without requiring the full version of the .NET Framework 4 to be present.

The list of the reference assemblies included in the .NET Framework 4 Client Profile can be found here.

Several project templates in Visual Studio 2010 target the .NET Framework 4 Client Profile. The following is a list of some project templates in Visual Studio 2010 that target the .NET Framework 4 Client Profile by default:

  • WPF Application

  • WPF Browser Application

  • WPF Custom Control Library

  • WPF User Control Library

  • Windows Forms Application

  • Windows Forms Control Library

  • Console Application

  • Empty Project

  • Window Service

If you attempt to reference an assembly in your project that is not included in the .NET Framework Client Profile, Visual Studio will display an error message. That is what happened to my colleagues.

Common errors include the following:

  • The type or namespace name "name" does not exist in the namespace "namespace". (Are you missing an assembly reference?)

  • Type "typename" is not defined.

  • Could not resolve assembly "assembly". The assembly is not listed as part of the "profile" Profile.

These errors can result from different actions:

  • You have referenced an assembly that is not Included in the Client Profile

  • You have referenced a project or assembly that targets a different version of the .NET Framework

  • You have re-targeted a project to a different version of the .NET Framework

  • You have re-targeted a project to a different version of the .NET Framework and references do not resolve

We fixed it by setting the Console Application project to target the full .NET Framework version 4 instead of the .NET Framework 4 Client Profile subset library. Here is how you do it.
Other solutions for other .NET Framework targeting errors can be found here.


EAVB_YTINPBKIEU

The Easiest Way to Add a Splash Screen to Your WPF Application

It has been a long time …

WPF applications do not start immediately. When an application is being loaded, there’s a delay while the CLR initializes the .NET environment and then starts the application.
Splash screens are typically used to notify the user that the application is in the process of loading.

The easiest way to add a splash screen to your WPF application is to have Visual Studio 2008 SP1 or later and to follow these steps:

1. Add an image file to your project. (you can use the BMP, GIF, JPEG, PNG or TIFF format)  .
2. Select the file in the Solution Explorer. 
3. Change the Build Action to SplashScreen.

The next time you run the application, the image will be shown immediately. Once the runtime environment is ready, and after the Application_Startup method has finished, your application’s first window appears, and the splash screen fades away within 300 milliseconds.

To remove the splash screen from your application you may either set the image’s Build Action to None or exclude the image from your project.

If you want to change the default fadeout duration (300 milliseconds), you’d have to take control over the SplashScreen.

First of all, locate the Main method within your App.g.cs file. Assuming you have followed the easy steps mentioned above to add the splash screen, your code will look something like this:

   1: /// <summary>
   2: /// Application Entry Point.
   3: /// </summary>
   4: [System.STAThreadAttribute()]
   5: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
   6: public static void Main() 
   7: {
   8:     SplashScreen splashScreen = new SplashScreen("mySplashScreenImg.jpg");
   9:     splashScreen.Show(true);
  10:     TestSplash.App app = new TestSplash.App();
  11:     app.InitializeComponent();
  12:     app.Run();
  13: }

The Show(true) call displays the splash screen image. The true parameter tells the application to close the splash screen automatically.

Modify the code to include the following:

   1: /// <summary>
   2: /// Application Entry Point.
   3: /// </summary>
   4: [System.STAThreadAttribute()]
   5: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
   6: public static void Main() 
   7: {
   8:     SplashScreen splashScreen = new SplashScreen("mySplashScreenImg.jpg");
   9:     splashScreen.Show(false); //false to close the splash screen manually
  10:     TestSplash.App app = new TestSplash.App();
  11:     app.InitializeComponent();
  12:     splashScreen.Close(TimeSpan.FromMilliseconds(5000)); //five seconds fade out !
  13:     app.Run();
  14: }

Now the splash screen’s fade out animation will take 5 seconds.