MarshalAs Attribute not supported in PCL for "Windows Phone Silverlight"? - silverlight

When I add the "Windows Phone Silverlight 8 (or 8.1)" target to my portable class library, the compiler flags MarshalAs:
error CS0246: The type or namespace name 'MarshalAs' could not be found (are you missing a using directive or an assembly reference?)
According to the MSDN documentation it is supported on WP Silverlight and in PCL.
Am I missing something here or is it really not available?
P.S.: Targeting Silverlight 5 shows the same problem...

Related

You must add a reference to assembly 'Microsoft.Data.Services.Client.Portable...' & NUGET

I have created a VS2013 solution that contains multiple projects. One of those projects is a portable class library targeting .NET 4.5+, Silverlight 5, Windows Store 8+ and Windows Phone 8 and this project contains a reference to an OData service in an accompanying web application.
The portable class library references Microsoft.Data.Services.Client.Portable (among others), added via nuget (WCF Data Services Client).
I have then added the portable class library to a WPF (.NET 4.5) application, a Windows Store application and a Windows Phone application and written some very basic test code to access the service. This works fine in Windows Store and Windows Phone.
The WPF application however will not compile. The errors are...
The type 'System.Data.Services.Client.DataServiceContext' is defined
in an assembly that is not referenced. You must add a reference to
assembly 'Microsoft.Data.Services.Client.Portable, Version=5.6.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The type 'System.Data.Services.Client.DataServiceQuery`1' is defined in an
assembly that is not referenced. You must add a reference to assembly
'Microsoft.Data.Services.Client.Portable, Version=5.6.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The thing is, I also added the WCF Data Services Client to the WPF application via nuget, but it does not add a reference to the portable library (packages\Microsoft.Data.Services.Client.5.6.0\lib\portable-net45+sl5+wp8+win8\Microsoft.Data.Services.Client.Portable.dll), instead adding a reference to the full framework 4.0 version (packages\Microsoft.Data.Services.Client.5.6.0\lib\net40\Microsoft.Data.Services.Client.dll) - which in turn is causing the error I am seeing.
Is there something I am doing wrong here or is this an error in the installation package? Note that if I delete the offending reference and add the alternative reference manually then all is well so though I have a work-around I would still like to know if I am the cause of the error.
Looking at the NuGet source code this behaviour seems to be by design.
The WCF Data Services Client contains assemblies for the following frameworks:
.NET Framework, v4.0
.NET Portable, net45, sl5, wp8, win8
Silverlight, v4.0
Installing this NuGet package into a project that targets .NET 4.5 will result in the .NET 4.0 assembly from the NuGet package being referenced. NuGet considers the more specific .NET framework to be a better match for your WPF project which targets .NET 4.5.
There is a comment in the NuGet source code about this when it looks for the best matching assembly in the NuGet package.
// Let's say a package has two framework folders: 'net40' and 'portable-net45+wp8'.
// The package is installed into a net45 project. We want to pick the 'net40' folder, even though
// the 'net45' in portable folder has a matching version with the project's framework.

How do I create a Silverlight 4 dll that Silverlight 3 applications cannot consume?

I have compiled a silverlight library that is set to Silverlight version 4 in the project properties. It consumes a dll with silverlight 4 dependencies. When I am on a system that only has silverlight 3 installed, I can reference the original silverlight library without error. At runtime I get an error about a class not existing in mscorelib. This is the behavior I would expect, except I would like to not be able to import the silverlight library at all if its not running silverlight 4. Am I missing something about how silverlight works, or should there be a way to prevent the consumption of my library before runtime on a system of an improper version?
To be fair, in Silverlight a library is a library is a library, so it assumes any missing assemblies will be supplied.
I think we may have to put this down to a "feature" of Visual Studio in that it does not exhaustively check dependencies for correct target types.

Silverlight + Web Application with WCF missing system.linq

I'm creating a little Silverlight LOB app. I created the app + web in Blend 4 and I've opened the solution in VS2010 to add the WCF service. When I do so, it shows an error on using System.Linq;. It says:
The type or namespace name 'Linq' does not exist in the namespace 'System'(are you missing an assembly reference?)
I had VS2010 create the WCF service and I've tried to re-add the reference in for .NET 4 System.Core.dll.
So newbie dev question... What did I do wrong :)
Check in the references if you DO see the System.Core.dll assembly.
If you do not see it, add it manually.
It should be in C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll (or in Program Files (x86) if your OS is x64).
After recompiling it should then work.

Referring to another project in XAML: Undefined CLR namespace

From the project "MarkdownEditorTest" I am trying to refer to controls from another project called "MarkdownEditor" but am getting the "Undefined CLR namespace" error as seen in the image below.
Isn't the way to refer to that project something like below?
xmlns:me="clr-namespace:MarkdownEditor"
Note that each project (C#, VB, etc.) creates its own assembly.
If it's in another assembly, you need to specify the assembly name:
xmlns:me="clr-namespace:MarkdownEditor;assembly=MarkdownEditor"
Note that generally each project in a solution creates a distinct assembly. And note that a project's name can be different than the assembly name. You can see the assembly name in the project's properties (in the application tab).
Also, be aware that a project's name can be different than the assembly name. You can see the assembly name in the project's properties (in the application tab).
I know that this may be a silly question, but have you included a reference to the other project in your visual studio project ?
I had the Same problem that occurred though I have added assembly. It's due to .net framework mismatch. So make sure your framework version of the assembly is equal or lower to the current project.
I hope this answer will help someone else.

Which dll has 'BusyIndicator' for silverlight?

I have installed Nov '09 silverlight 3 toolkit. Referenced System.Windows.Control from C:\Program Files\Microsoft SDKs\Silverlight\v3.0 Libraries\Client\System.Windows.Controls.dll
but when I compile my code I am getting
"Error 6 The type or namespace name 'BusyIndicator' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)"
I opened the dll in object browser and I could not find the busyindicator either. Could some one please tell me which dll has the Busy Indicator?
I found the following link regarding the same issue but did not say which dll has this class.
Thanks,
It's the System.Windows.Controls.Toolkit assembly.
Direkt link to the source code.
Generally, I'd strongly recommend to switch to 4.0 though.

Resources