Thursday, June 10, 2010

Silverlight Unit Test Project Templates Compile Error

Introduction

Silverlight Unit Test project templates work perfect fine Silverlight Application project templates for Silverlight 4 and Visual Studio 2010. They will compile right off the bat. However Silverlight Business Application project templates will not immediately compile with a Silverlight Unit Test project template.

If you were to:

  1. Create a Silverlight Business Application.
  2. Then add Silverlight Unit Test. Enable WCF RIA Services and select the Business Application project as the Host.
  3. Then compile without making any changes.

What will result is compile errors and you will get different compile errors based on using C# or VB.net

C# Template

The following are the errors you would see in C#. To resolve these errors all you need to do is add a reference to the Silverlight Business Application to the Silverlight Unit Test project.

The annoying thing about this bug is that when you add the Silverlight Unit Test project the expectation is that this reference would be created since you selected the Business Application as the hosting project. You do not have to do this with Silverlight Applications.

Error 1 The type or namespace name 'Resources' does not exist in the namespace 'BusinessApplication1.Web' (are you missing an assembly reference?) C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.cs 299 101 SilverlightTest1

Error 2 The type or namespace name 'Resources' does not exist in the namespace 'BusinessApplication1.Web' (are you missing an assembly reference?) C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.cs 334 92 SilverlightTest1

Error 3 The type or namespace name 'Resources' does not exist in the namespace 'BusinessApplication1.Web' (are you missing an assembly reference?) C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.cs 367 138 SilverlightTest1

Error 4 The type or namespace name 'Resources' does not exist in the namespace 'BusinessApplication1.Web' (are you missing an assembly reference?) C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.cs 398 103 SilverlightTest1

Error 5 The type or namespace name 'Resources' does not exist in the namespace 'BusinessApplication1.Web' (are you missing an assembly reference?) C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.cs 437 95 SilverlightTest1

VB.net Template

You will get a couple more errors when doing VB.net. To resolve first add a reference to the Business Application project as we did for the C# solution. That will resolve errors 6, 8, and 9 however 1 to 5 will still remain. This is pretty confusing because doing that resolved the same issues for VB.net.

Next you need to either the following:

  1. Go to the Silverlight Unit Test Project properties. Change the Root Namespace to BusinessApplication1 in this case.
  2. Or go the BusinessAppllication1.Web project (the RIA Services project), go to the Models folder, and modify RegistrationData.vb. You will need to remove all reference to RegistrationDataResources in that class. What is happening is the RegistrationDataResources.resx is not projecting to the Silverlight Unit Test project and subsequently creating reference errors.

Error 1 Type 'BusinessApplication1.RegistrationDataResources' is not defined. C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.vb 305 79 SilverlightTest1

Error 2 Type 'BusinessApplication1.RegistrationDataResources' is not defined. C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.vb 336 70 SilverlightTest1

Error 3 Type 'BusinessApplication1.RegistrationDataResources' is not defined. C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.vb 365 117 SilverlightTest1

Error 4 Type 'BusinessApplication1.RegistrationDataResources' is not defined. C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.vb 392 81 SilverlightTest1

Error 5 Type 'BusinessApplication1.RegistrationDataResources' is not defined. C:\BusinessApplication1\SilverlightTest1\Generated_Code\BusinessApplication1.Web.g.vb 427 73 SilverlightTest1

Error 6 'FriendlyName' is not a member of 'SilverlightTest1.Web.User'. C:\BusinessApplication1\SilverlightTest1\Generated_Code\Models\Shared\User.shared.vb 10 45 SilverlightTest1

Error 7 'FriendlyName' is not a member of 'SilverlightTest1.Web.User'. C:\BusinessApplication1\SilverlightTest1\Generated_Code\Models\Shared\User.shared.vb 11 28 SilverlightTest1

Error 8 'Name' is not a member of 'SilverlightTest1.Web.User'. C:\BusinessApplication1\SilverlightTest1\Generated_Code\Models\Shared\User.shared.vb 13 28 SilverlightTest1

1 comment:

Paradigm said...

It has something to do with RIA. I created a silverlight application from template with Enable RIA enabled. It gave me these errors. I deleted it and created one with RIA disabled, and the error didn't show up.