Monday, 30 June 2008

XBAP applications and Strong Naming.

One of the first things that is hammered into you when start reading up on XBAP applications is that they run with Partial Trust. There are ways to get your XBAP application running with full trust but this is not the typical scenario (and that topic is worth a whole series of blog posts).

When you Strong Name an assembly, by default the assembly will not allow Partially Trusted callers. As the sandbox in which your XBAP applications run is running with Partial Trust, this means that you will get the following error in the browser when you try to run your application

Startup URI: C:\dir\MyApplication.xbapApplication Identity: file:///C:/dir/MyApplication.xbap#MyApplication.xbap, Version=x.x.x.x, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=msil/MyApplication.exe, Version=x.x.x.x, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=msil, type=win32
System.Security.SecurityException: That assembly does not allow partially trusted callers. at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Windows.Interop.PresentationApplicationActivator.CreateInstance(ActivationContext actCtx) at System.Activator.CreateInstance(ActivationContext activationContext) at System.AppDomain.InternalRemotelySetupRemoteDomainHelper(Object[] args) at System.Threading.Thread.CompleteCrossContextCallback(InternalCrossContextDelegate ftnToCall, Object[] args) at System.AppDomain.nCreateInstance(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor) at System.Runtime.Hosting.ApplicationActivator.CreateInstanceHelper(AppDomainSetup adSetup) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Windows.Interop.PresentationApplicationActivator.CreateInstance(ActivationContext actCtx) at System.Windows.Interop.ApplicationLauncherXappDebug.Initialize() at System.Windows.Interop.DocObjHost.MS.Internal.AppModel.IBrowserHostServices.Run(String path, String debugSecurityZoneURL, String viewerUri, String fragment, String applicationId, MimeType mime, Object streamContainer, Object ucomLoadIStream, String userAgentString, Boolean isDebugMode, String progressAssemblyName, String progressClassName, String errorAssemblyName, String errorClassName)The action that failed was:LinkDemandThe method that caused the failure was:Void Main()


To prevent this problem, you need to mark your XBAP assembly with the AllowPartiallyTrustedCallersAttribute, for example:

[assembly: AllowPartiallyTrustedCallers]


With this Attribute your XBAP application will now run.

Wednesday, 25 June 2008

Microsoft Dynamics CRM 4.0 install error "The instance name must be the same as computer name."

If you are installing Microsoft Dynamics CRM 4.0 to a computer that you have renamed, this can cause problems depending on when you installed SQL Server 2005. If you installed SQL Server before you renamed the box, you will receive the following error regarding SQL Server 2005 when the installer does a system check:

"The instance name must be the same as computer name."

To fix this problem you need to update the name of the machine in SQL Server by executing the following:

sp_dropserver 'OldMachineName'
GO
sp_addserver 'NewMachineName', local
GO

You will also need to restart the SQL Server service. Please note you can't use this command to change the instance suffixes. For example you can NOT change "serverA\SomeInstance" to "serverA\AnotherInstance", you may only change "serverA\SomeInstance" to "serverB\SomeInstance".

For more information see the following MSDN article: http://msdn.microsoft.com/en-us/library/ms143799.aspx

You may also need to update Reporting Services: http://msdn.microsoft.com/en-us/library/ms345235.aspx

This situation can easily arise if you have a virtual envrionment and are cloning machines.

Monday, 7 April 2008

Windows 2008 Server Core does not support managed code

Yes, you read the title correctly.

The Windows 2008 Server Core SKU does not support any managed code, that means no .NET applications at all. Period.

More info in the "Server Core Installation Option of Windows Server 2008 Step-By-Step Guide" here: http://technet2.microsoft.com/windowsserver2008/en/library/47a23a74-e13c-46de-8d30-ad0afb1eaffc1033.mspx?mfr=true

Apple Safari for Windows

Apple has recently release its Safari browser for Windows: http://www.apple.com/safari/

While I hate the fonts (no where near as good as Internet Explorers Clear Type goodness) the browser itself is blisteringly fast. I use Newsgator On-line as my RSS aggregator and under IE it runs fairly slow (there is alot of JavaScript). Under Safari it is incredibly fast.

The browser wars are here again.

Sunday, 6 April 2008

MSBuild, VS2008 and "Invalid search path"

Since installing VS2008 I have been getting the following error when using the VS2008 Command Prompt and trying to build Visual Studio solutions or trying to run "local" Team Builds:

CSC : error CS1668: Warning as Error: Invalid search path 'C:\Program Files\\Microsoft SDKs\Windows\v6.0A\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '

The reason for this is that the environment variables configured for this command console assume you have installed the C++ components with Visual Studio (which I did not install for the sakes of disk space).

The easiest way to solve this problem is to create the path. The "'C:\Program Files\\Microsoft SDKs\Windows\v6.0A\" path should already exist, so just create a "Lib" folder at that location.

Its a simple fix but working out why this was a problem was tricky, it niggled me why a fairly straight forward install of VS2008 would have a not insignificant problem.

Thursday, 13 March 2008

Generating a Schema for the BizTalk SQL Adapter

To call a Stored Procedure from BizTalk you need to use the SQL Adapter. This requires you add a special Schema to your BizTalk application, this Schema is generated by a wizard in Visual Studio (the wizard is installed as part of the BizTalk SDK).

This process isn't as straight forward as it should be an its easy to end up with a Schema where the value returned from the Stored Procedure is represented by a "Success" Element of "anyType which is useless.

Firstly, you must have a Stored Procedure that that returns a result set using "FOR XML AUTO". Secondly, when you run through the wizard you must add "XMLDATA" to the end of the Stored Procedure (and remove it after you have generated the Schema). The XMLDATA clause causes SQL Server to return the Schema for the result set (as well as the result). So, when you go through the wizard you must have a stored procedure looking something like this:

SELECT ColumnA, ColumnB FROM MyTable FOR XML AUTO, XMLDATA

After you have generated your schema, remove the "XMLDATA" clause to leave:

SELECT ColumnA, ColumnB FROM MyTable FOR XML AUTO

When you run through the wizard, most of the values you need to enter are obvious but when you get to the "Schema Information" screen, you need to change the "Port Type" to "Send".

When you get to the "Statement Information" screen, you need to enter valid values into the "Value" column (click the Value cell twice to enter data). Then hit "Generate", then hit "Next".

The SQL Adapter Wizard does not seem to support "FOR XML EXPLICIT", you get an error that says "the required attribute 'name' is missing". However, I would guess that if you can generate the boiler plate Schema using "FOR XML AUTO," you should be able to change your Stored Procedure and then manually edit the Schema generated by the Wizard to match what your XML EXPLICIT format.

Wednesday, 5 March 2008

Microsoft SharedView Version 1.0 available

Microsoft’s desktop sharing application, called SharedView, is out of beta. Think of the application as “Live Meeting”-lite, where up to 15 people can all share one desktop.

Download from here: http://www.connect.microsoft.com/content/content.aspx?ContentID=5306&SiteID=94

Monday, 3 March 2008

Gated Check-ins and Team Foundation Server

There was a discussion lately on the ALT.NET mailing list about the merits of NAnt versus MSBuild. This discussion expanded to encompass the various build engines there are outt here such as CruiseControl.NET (open source from ThoughtWorks) and TeamCity (free for non-Enterprise use, by JetBrains).

Someone mentioned the "private build" feature of TeamCity where by you ask the build server to do a build of what you currently have but without actually checking in your code to the source tree.

I pointed out that this feautre is also supported by Team Foundation Server through an open source framework exisits called Gauntlet (http://www.opengauntlet.org/). The elevator pitch from the Gauntlet web site is as follows:

"OpenGauntlet...mimics a fundamental feature of Microsoft's internal development system (codenamed Gauntlet), also known as "Gated Checkins". It avoids the problems associated with large development teams whereby a single developer will check in non-compiling code, which subsequently causes delays in the development life cycle as the team waits for the issues to be resolved. It can also be configured to disallow check ins if the proposed code changes break the unit tests. The central principle is that users are not allowed to check code directly into source control. Instead, they shelve their changes with a specific naming prefix when they are ready to check some changes in, and OpenGauntlet unshelves their changes into a temporary workspace, checks the changes compile and pass unit tests, and then checks the changes into source control under the requesting developer's username."

I've not taken the plunge with setting this up yet, I have an upgrade to TFS2008 to do first, but it looks like a must have. Here's to less "red" builds!

Monday, 25 February 2008

NServiceBus

I subscribed to Udi Dahan's blog recently (http://udidahan.weblogs.us/). I saw him present a session called "Designing High Performance, Persistent Domain Models" at Tech-Ed 2007 in Barcelona. It was one of the best sessions I saw during the week. How he got a talk with NHibernate demo material into Tech-Ed I'll never know.

I read through some of the old blog posts to catch up on what he'd been doing since Tech-Ed and I noticed he'd been working on a open source messaging framework called "NServiceBus" (http://www.nservicebus.com/).

This is interesting because I frequently encounter projects that require some kind of message bus with pub/sub features but don't want to take the plunge with BizTalk as its either too heavy weight or the license cost is prohibitive.

The project seems to be progressing, version 1.7 has been released at the time of writing and there is an active news group (http://tech.groups.yahoo.com/group/nservicebus/).

I will evaluate the framework at some point and report back.


Saturday, 23 February 2008

WCF Services and Dependency Injection with Castle

You might encounter a situation where you are leveraging the dependency injection design pattern in your application. At first this might seem problematic to implement if you are using WCF Services.

For example, you may have the following classes:

public interface ICustomerRepository

{

    // Code

}

 

public class CustomerRepository : ICustomerRepository

{

    // Code

}

 

[ServiceContract]

public interface ICustomerService

{

    [OperationContract]

    void AddCustomer(AddCustomerRequest addCustomerRequest);

}

 

public class CustomerService : ICustomerService

{

    private readonly ICustomerRepository _customerRepository;

 

    public CustomerService(ICustomerRepository customerRepository)

    {

        _customerRepository = customerRepository;

    }

 

    /// <remarks />

    public void AddCustomer(AddCustomerRequest addCustomerRequest)

    {

        // Do stuff

        // _customerRepository.SomeMethod(someParameter);

    }

}

The problem is that as your WCF Service is instantiated by the WCF plumbing, you don't have any control over the creation of this class. How do you "inject the dependency"? How do you supply the "ICustomerRepository" to the "CustomerService"? If you are using the Windsor Container part of the Castle framework (http://www.castleproject.org/) as your Component Container, it has a Facility that enables us to do this.

Using the "CustomerService" example above, you need to do three things in your Web Services project.

1. Modify the .svc file

Create your "CustomerService.svc" file as follows:

<%@ ServiceHost Service="CustomerService" Factory="Castle.Facilities.WcfIntegration.WindsorServiceHostFactory, Castle.Facilities.WcfIntegration" %>

Note the differences between a standard svc file.

2. Modify your Global.asax

Next you need to instantiate a Windsor Container, do this in a Global.asax file as follows (you might have to add one to your project):

public class Global : HttpApplication

{

    private readonly IWindsorContainer _container =

        new WindsorContainer(new XmlInterpreter());

 

    protected void Application_End(object sender, EventArgs e)

    {

        if (_container != null)

            _container.Dispose();

    }

 

    protected void Application_Start(object sender, EventArgs e)

    {

        WindsorServiceHostFactory.RegisterContainer(_container.Kernel);

    }

}

3. Configure Castle

Configure Castle in the usual way, you need to include your "CustomerService" and "CustomerRepository" classes in the configuration. An example is as follows:

<configSections>

  <section

    name="castle"

    type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />

</configSections>

 

<castle>

  <components>

    <component

      id="CustomerRepository"

      service="Acme.PetSop.ICustomerRepository, myAssembly"

      type="Acme.PetSop.CustomerRepository, myAssembly" />

    <component

      id="CustomerService"

      service="Acme.PetSop.ICustomerService, myAssembly"

      type="Acme.PetSop.CustomerService, myAssembly" />

  </components>

</castle>

Please note that your "Service" value in the .svc file must match the "id" value in the Castle configuration.

You need to have the "Castle.Facilities.WcfIntegration.dll" assembly referenced by your Web Application project. At the time of writing this assembly is not in the latest Castle release and can only be found in the nightly builds.

The Castle documentation for the WCF Facility can be found here: http://www.castleproject.org/container/facilities/trunk/wcf/index.html


About Me