Recently, I have some time to look into the solution for sharing code between .NET and Silverlight again. It was an annoyance which everyone of us (including developers around the world) discovered, where we can't reuse our .NET classes in Silverlight. Any attempt to add reference to our .NET assemblies will land us the following error message:
"You can only add project references to other Silverlight projects in the solution."
If you are developing layered or multi-UI applications that involves Silverlight, then you would have encountered this error. This is not really a bug but actually is by design since both Silverlight and .NET don't share the same runtime. This is indeed bad news for those of us who try to follow proper architecture design practices since we are unable to share our entity classes.
If you packed everything to one WCF service, then you shouldn't have any problems because the "Add Service Reference" option in Visual Studio would have generated replicas of the entities into the Silverlight project. However, if you have separate services i.e. a WCF service to handle standard calls and a Workflow Service that runs workflows and both requires the same set of entities, then you will immediately run into issues because the replicas generated on both service references will not be compatible.
There is currently no out-of-the-box intelligent solution for this issue. This is a tooling limitation - I blame it on svcutil.exe. Most developers after several futile attempts will just try to manually replicate the entity classes to their Silverlight projects. This will solve the add reference issue but will introduce code inconsistencies should the entity classes are updated in future.
Fortunately, Visual Studio provides us with the "Add As Link" feature to allow us to share the same code files across multiple projects. However, this is somewhat a pain as well since we need to keep the projects synchronized when we add/remove items.
By luck, I came across this handy Visual Studio Extension - Project Linker which was part of the PRISM project. This neat tool allows us to "link" Visual Studio projects together keeping them fully synchronized so that we can have projects that share the same code base but target different platforms. It was originally designed for sharing code between WPF and Silverlight. You can also check-out the documentation here - very useful when you need to "unlink" projects ;)
So there we have it. Not a very elegant solution but at least it helps reduce the redundancy and ensure synchronization of our code.
Home » Silverlight » Sharing Code Between .NET and Silverlight
Sharing Code Between .NET and Silverlight
21:43
Jurnalis Jalanan
Labels:
.NET,
Layered Architecture,
Silverlight
Popular Post
-
S4 / 1.984 cc / 200 PS / 207 ft/lb (280 Nm) @ 1.700 - 5.000 / turbo / AWD (click images for a larger view)
-
these photos are from a gallery I posted http://justacarguy.blogspot.com/2011/04/gourmet-feed-trucks-were-gathered-to.html when I accident...
-
Honda nearing capacity at Swindon Honda's UK factory in Swindon, which builds the Civic and CR-V models , will be working at its peak o...
-
Boxstr continues being absolutely useless. Seems like it's (occasionally) possible to download songs previously uploaded, but for the p...
-
Electric / 63 PS / 133 ft/lb (180 Nm) / 0 - 62 mph (100 km/h): 11,4 s / Vmax: 91 mph (146 km/h) / range: 115 miles (185 km) (click images ...
-
For the second time this summer, Kia is teasing the upcoming Carens compact MPV with a set of sketches that were released in advance of the...
-
So, yeah. There's always a simmering debate among writers about whether or not to respond to bad reviews. In one recent article titled W...
-
The all-new 2013 ATS premium compact sedan will be taking the spotlight on Cadillac’s stand at the upcoming Paris Motor Show as the automak...
-
SS: V8 / 6.162 cc / 432 PS / 420 lb/ft (569 Nm) @ 4.600 ZL1: V8 / 6.162 cc / 556 PS / 556 lb/ft (746 Nm) @ 3.800 (click images for a larger ...
-
V8 / 4.806 cc / 430 PS / 384 ft/lb (520 Nm) @ 3.500 / AWD / 0 - 62 mph (100 km/h): 4,5 s / Vmax: 179 mph (288 km/h) (click images for a la...
No comments:
Post a Comment