in

mscommunity.net

Interactive mscommunity.net online activities

DamirDobric

srpanj 2008 - Posts

  • .NET Frameworks comparison and .NET3.5 SP1

    The relationship of the .NET Framework versions 2.0, 3.0, and 3.5 differs from the relationship of versions 1.0, 1.1, and 2.0. The .NET Framework versions 1.0, 1.1, and 2.0 are completely separate from each other, and one version can be present on a computer regardless of whether the other versions are present. When versions 1.0, 1.1, and 2.0 are on the same computer, each version has its own common language runtime, class libraries, compiler, and so forth. Applications can choose whether to target version 1.0, 1.1, or 2.0. For more information, see Side-by-Side Execution.

    I would like to relate to this MSDN article, which describes some high level differences.

    .NET Framework version 3.5 Service Pack 1 provides the following new features and improvements:

    • ASP.NET Dynamic Data, which provides a rich scaffolding framework that allows rapid data driven development without writing code, and a new addition to ASP.NET AJAX that provides support for managing browser history (back button support). For more information, see What’s New in ASP.NET and Web Development.
    • Core improvements to the common language runtime that include better layout of .NET Framework native images, opting out of strong-name verification for fully trusted assemblies, improved application startup performance, better generated code that improves end-to-end application execution time, and opting managed code to run in ASLR (Address Space Layout Randomization) mode if supported by the operating system. Additionally, managed applications that are opened from network shares have the same behavior as native applications by running with full trust.
    • Performance improvements to Windows Presentation Foundation, including a faster startup time and improved performance for Bitmap effects. Additional functionality for WPF includes better support for line of business applications, native splash screen support, DirectX pixel shader support, and the new WebBrowser control.
    • ClickOnce application publishers can decide to opt out of signing and hashing as appropriate for their scenarios, developers can programmatically install ClickOnce applications that display a customized branding, and ClickOnce error dialog boxes support links to application-specific support sites on the Web.
    • The Entity Framework is an evolution of the existing suite of ADO.NET data access technologies. The Entity Framework allows developers to program against relational databases in terms of application-specific domain models instead of the underlying database models. For more information see Getting Started with the Entity Framework. The Entity Framework introduces some additional features, including support for new SQL Server 2008 types, default graph serialization of Entities, and the first broad public release of the Entity Data Source. With this release, the Entity Framework supports the new date and file stream capabilities in SQL Server 2008. The graph serialization work helps developers who want to build Windows Communication Foundation (WCF) services that model full graphs as data contracts. The Entity Data Source provides a traditional data source experience for ASP.NET application builders who want to work with the Entity Framework.
    • LINQ to SQL includes new support for the new date and file stream capabilities in SQL Server 2008.
    • The ADO.NET Data Services Framework consists of a combination of patterns and libraries, which enable data to be exposed as a flexible REST (Representational State Transfer)-based data service that can be consumed by Web clients within a corporate network or across the Internet. The ADO.NET Data Services Framework makes data service creation over any data source. A conceptual view model of the underlying storage schema can easily be exposed through rich integration with the ADO.NET Entity Framework. Services created using the ADO.NET Data Services Framework, as well as compatible Windows Live (dev.live.com) services, can be easily accessed from any platform. For client applications running on Microsoft platforms, a set of client libraries are provided to make interaction with data services simple. For example, .NET Framework-based clients can use LINQ to query data services and a simple .NET Framework object layer to update data in the service.
    • Windows Communication Foundation now makes the DataContract Serializer easier to use by providing improved interoperability support, enhancing the debugging experience in partial trust scenarios, and extending syndication protocol support for wider usage in Web 2.0 applications.
    • The .NET Framework Data Provider for SQL Server (SqlClient) adds new support for file stream and sparse column capabilities in SQL Server 2008.

    Download BETA:

    http://www.microsoft.com/downloads/details.aspx?FamilyId=8C36ACA4-E947-4760-9B05-93CAC04C6F87&displaylang=en

  • Assembly Permission Checker

    With this tool, you can check assembly permissions defined by CASPOL. It is a very simple console application based on .NET 2.0 with source code.

  • Mimetypes required for VSTO and ClickOnce

    Following mime types should be registered in IIS, when using VSTO and ClickOnce:

    .application
    application/x-ms-application

    .manifest
    application/x-ms-manifest

    .deploy
    application/octet-stream

    .deploy
    application/x-ms-vsto

  • Registering user as an Admin for device

    The BizTalk RFID provides a security mechanism called device-level security. Users who are registered as device admins (entity admins) are by default permitted to execute all methods of DeviceManagerProxy class.

    By obtaining the instance of this class the one can perform any administrative operation on device and execute any sync command. Sometimes it is also required (or in general possible) to execute some sync commands by using of device manager proxy instance, which are not necessarily an administrative task. In this case the caller does not have to be a device-admin, but sotemies it should. For example, following
    example shows how to execute command by using of the proxy class:
     

    DeviceManagerProxy proxy = new DeviceManagerProxy(m_Host);
    Guid connId = proxy.OpenConnection("mydevice");
    proxy.ExecuteCommandForConnection("mydevice", "source", connId, cmd);


    Depending on what 'cmd' is, admin permission can be required or not. For none-administrative tasks I use rather following example:

    using (DeviceConnection connection = new DeviceConnection("Host", "Device"))
    {
     
    connection.Open();

      Command cmd = connection.ExecuteCommand(null, rfidCommand, null);

      . . .
    }

    Following picture illustrates how to add a user in the list of device administrators.
    image image


    To get a feeling what methods are implemented in DeviceManagerProxy, here is a list of all methods:

    [Serializable]

        public sealed class DeviceManagerProxy : ProxyBase, IDeviceManager

        {
            public DeviceManagerProxy();

            public DeviceManagerProxy(string host);

            public void AddDevice(DeviceDefinition device, string parentDeviceGroup, bool addInOfflineMode);

            public void AddDeviceEntitySecurityRecord(string deviceEntity, string accountName, DeviceEntitySecurityPrivilege privilege);

            public FirmwareComparisonInformation CheckFirmwareCompatibility(string deviceName, string firmwareLocation);

            public void CheckpointDevice(string deviceName);

            public void CloseConnection(string deviceName, Guid connectionId);

            public void CreateDeviceGroup(DeviceGroupDefinition deviceGroupDefinition, string parentDeviceGroupName);

            public void DeleteDevice(string deviceName);

            public void DeleteDeviceGroup(string deviceGroup);

            public void DisableDevice(string deviceName);

            public void EnableDevice(string deviceName);

            public Command ExecuteCommandForConnection(string deviceName, string sourceName, Guid connectionId, Command command);

            public Command ExecuteDedicatedCommand(string deviceName, Command command);

            public DeviceDefinition[] GetAllDevices();

            public Collection<DeviceGroupDefinition> GetAllSubDeviceGroups(string deviceGroup);

            public string[] GetAllSubDevices(string deviceGroup);

            public DeviceStatus GetCurrentDeviceStatus(string deviceName);

            public DeviceDefinition GetDevice(string deviceName);

            public Collection<DeviceCapability> GetDeviceCapabilities(string deviceName);

            public DeviceEntitySecurity GetDeviceEntitySecurity(string deviceEntity);

            public Dictionary<PropertyKey, RfidDevicePropertyMetadata>

            GetDevicePropertyMetadata(string deviceName, string propertyGroupName);

            public DeviceStatus[] GetDeviceStatus(string[] deviceNames);

            public DeviceVersion GetDeviceVersion(DeviceVersionInfo info);

            public Collection<DeviceVersionInfo> GetDeviceVersionInfos(string deviceName);

            public DeviceVersion[] GetLatestDeviceVersions(string[] deviceNames);

            public Collection<TagPrintedEvent> GetPrintStatus(string deviceName);

            public string[] GetPropertyGroupNames(string deviceName);

            public bool GetSecurityInheritance(string deviceEntity);

            public Dictionary<string, PropertyProfile> GetSources(string deviceName);

            public void KillConnection(string deviceName);

            public void MoveEntityToDeviceGroup(string sourceDeviceEntity, string targetDeviceGroup);

            public Guid OpenAdministrationConnection(string deviceName);

            public Guid OpenConnection(string deviceName);

            public void RebootDevice(string deviceName);

            public void RemoveDeviceEntitySecurityRecord(string deviceEntity,
            string accountName, DeviceEntitySecurityPrivilege privilege);

            public void RemoveSecurityInheritance(string deviceEntity, bool copyEffectivePermissions);

            public void RenameDevice(string oldName, string newName);

            public void RenameDeviceGroup(string oldDeviceGroupName, string newDeviceGroupName);

            public void SetSecurityInheritance(string deviceEntity);

            public void UpdateDevice(DeviceDefinition device, bool includeAuthInfoInUpdate);

            public void UpdateDeviceGroup(DeviceGroupDefinition deviceGroupDefinition);

            public PropertyProfile ValidateConnection(UserDeviceInformation deviceInfo, AuthenticationInformation authInfo);

        }

    Related article: http://msdn.microsoft.com/en-us/library/bb749827.aspx

  • Asp.Net Compiling behind the scene

    When working in big projects (of type ASP.NET) you may notice (for sure) that your development environment (means VS) does not perform well (understood bad). This was a reason to investigate what happen behind the scene. This post contains some interesting details which could help you to organize your solution (project) to build more quickly.

    For this reason I build the small web.app shown below:

    image
    This application contains one root page (Default.aspx) and two controls in subfolder Controls. The Default.aspx page looks like shown below.

    image
    Note that this pages should be the start page. This is important, because otherwise the build process on start of application will produce different result (about this a bit later).
    The page shows how to load the control from specified path. If you set the breakpoint exactly at this line (Page.LoadControl) and open in explore the temporary ASP.NET folder of this application you will see following content:

    image 

    The content of this folder is created each time the application is started for the first time after build. That is when the very first page is requested. If some files are already existing, they will be deleted and created again.
    To understand what here happened, open the file Default.aspx.*.compiled. Note that on you machine this name will look similar, but different (that's why '*'). The content of this file looks like:

    image

    VirtualPath specifies what has been compiled? Assembly specifies the DLL where the compiled type (page or control) has been linked to. All files containing the hash value (automatically generated) 'qvgqgilp' are some kind of result of compiling of the type.
    That means, if you delete all this files, you will remove that type fully from the runtime. Otherwise, if you copy these files somewhere and deploy them on the runtime, the type will be used as it would have been regularly produced by asp.net compiler.

    Now if we step over the line Page.LoadControl, the ASP.NET will look for WebUserControl1.ascx and notice that it is not compiled.

    Type ctrlType = Type.GetType("ASP.controls_webusercontrol1_ascx");

    Now, you probably think, that the next logical step is to compile the control WebUserControl1.ascx. This is true, but ASP.NET compiler will additionally compile all controls contained in the subsubfolder (in this case 'Controls').
    This is very important, because if you have many controls in that folder, this step could take long time. Imaging, for very simple control, asp.net compiler needs approximately two seconds. This means just 20-30 controls could take two minutes.

    That means that currently executing line would take two minutes and user would probably get a timeout in the browser. Personally I do not know anybody who would wait longer than 10 seconds :)

    Anyhow, following picture shows what has been compiled (produced) at the moment when (just before) the WebUserControl1.ascx has been loaded (selected files are produced):

    image

    Files marked in red frame shows that the page dummy.aspx and two controls have been compiled. That means, all types in the folder 'Controls'.
    Another possibility to load the control is:

    Control fromType = this.LoadControl(ctrlType, null) as UserControl;

    This statement does not enforce compiling of the control. If the control has not been previously compiled the statement will fail.To enforce controls to be compiled, the simplest way would be to open the page Dummy.apx in the folder where all controls are stored. If you decide to use this approach, the start up will be slow, but loading of controls very fast.

    Note that statement above will not work anyhow. Use rather Assembly.GetType()!

    The ultimate solution

    Hope this help you to understand what's going un behind the scene. Unfortunately, what ever you do at some time controls have to be compiled and this will take a time. :(
    All I described in this post is related to development only. That is, you write code and press F5 in IDE. Part of building of application happens in the runtime after the application has been started. In the productive environment this wouldn't be the final solution. The real deployment concept should be able to perform all slow building tasks in the design time of the application.
    The solution for this is ASPNET.COMPILER.EXE.

    The compiler can be found at this location..

    FileInfo f = new FileInfo(Type.GetType("System.String").Assembly.Location);

    .. and this is how to pre-compile the application:

    C:\Program Files\Microsoft Visual Studio 9.0\VC>aspnet_compiler.exe  -c -v / -p "D:\MyProjects\DaenetProjects\DiverseTests\WebAppBuildProcessSample\WebAppBuildProcessSample" -f "c:\Temp\WebAppBuildProcessSample"

    First specified path is the development folder where the application's project-file (not solution file) is stored and rthe second one is the output folder which can be mapped to IIS virtual folder.


    Here is the console output if all works fine:

    Utility to precompile an ASP.NET application
    Copyright (C) Microsoft Corporation. All rights reserved.

    C:\Program Files\Microsoft Visual Studio 9.0\VC>


    And finally this is the result of the build:

    image

    As you see all assemblies are already there. If you don't like aspnet_compiler try this [DMERGE] tool.

    Posted srp 16 2008, 10:36 by anonymous
    Filed under:
  • Service Model Extensions

    By extending of WCF there are several types of possible extensions in the configuration file. In general there are three main groups of extensions:

    1. Behavior Extensions
    2. Binding Element Extensions
    3. Binding Extensions

    Here is an example which can be found in the machine.config file.

    image

    Following picture shows how to implement the custom binding.
    image

    To do this, it is necessary to implement three different classes, which derive from Binding, StandardBindingCollectionElement and StandardBindingElement.

    Posted srp 13 2008, 12:50 by anonymous
    Filed under:
  • WCF/ASP.NET Request Throttling and tuning

    Just wanted to recommend this very interesting Dong's post about WCF and ASP.NET threading in IIS:  http://blogs.msdn.com/wenlong/archive/2008/04/21/wcf-request-throttling-and-server-scalability.aspx.

    Posted srp 09 2008, 12:21 by anonymous
    Filed under:
  • .NET Framework Versions in Registry

    .NET 1.0: Software\\Microsoft\\.NETFramework\\Policy\\v1.0

    .NET 1.0: SP1 Software\\Microsoft\\Active Setup\\Installed Components\\{78705f0d-e8db-4b2d-8193-982bdda15ecd}

    .NET 1.0: SP2 Software\\Microsoft\\Active Setup\\Installed Components\\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}

    .NET 1.1: Software\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322

    .NET 2.0: Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727 (Version: 2.0.50727.1434)

    .NET 3.0: Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0\\Setup

    .NET 3.0 SP: Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0 (Version 3.0.04506.648)

    .NET 3.5: Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5 (Version 3.5.21022.08)

Powered by Community Server (Commercial Edition), by Telligent Systems