I have a problem with the Marshal class in the System.Runtime.InteropServicenamespace.
In my project map I have a Windows Phone 8, a Windows Store and a Portable Class Library project.
I can easily use the Marshalclass in the Windows Phone 8 and Windows Store project, but not in the Portable Class Library. This class can not be found there.
By settings, the Portable Class Library support the .Net 4.5 Framework, Windows Phone OS 8.0 and Windows Store.
You cannot access Marshal class in Portable Class Library project with support of anything else than .NET Framework and Windows Store App - by design of .NET Framework as stated in resolution of relevant bug of .NET Framework.
Added below a screenshot as at MS Connect they tend to delete defects (as here) from time to time:
Related
I have developed a UWP class library , and it is already used in various projects.
Now I want to make this UWP class library to support WindowsAppSdk apps too.
When I try to refer UWP Library in WindowsAppSdk app, getting error like "Project is not compatible".
My UWP class library min supported version - Windows 10 fall creators update (16299).
Should I recreate my UWP Library as WindowsAppSdk library ?
Can anyone help me understand this
Thanks
Noorul.
Should I recreate my UWP Library as WindowsAppSdk library ?
No, but you should convert it into a .NET Standard library that can be consumed by both UWP and WinUI (.NET) applications, and any other type of application whose runtime implementation supports the version of the .NET Standard specification that you choose to target.
UWP apps cannot consume librararies that are targeted against a specific platform such as .NET and vice versa. That's where .NET Standard comes in. It enables you to share code across multiple .NET implementations and platforms.
I have a Class Library Project that I would like to make use of on the Windows Phone and Silverlight Apps (Windows 8.1). Effectively turn it into a Class Libary (Portable).
My Class Library has a Window base class (inherits from System.Windows.Window), however this is not available in portable class libraries.
To make this simple:
1) Is it possible to create a universal class library that will allow me to use it on the windows desktop, as well as windows 8.1 and windows phone 8.1?
2) How can I add a class that inherits from System.Windows.Window in a portable class library? Do I need to use pre-processor directives? How would I go about referencing System.Windows?
Am I going about this in the right way? Is there a better solution?
You can't. A PCL only allows a specific subset of the .NET framework. Depending on your configuration, this is more or less of the entire framework.
What you can't do, in any way, is including assemblies and types that are not compatible with the PCL, like in this case System.Windows.Window.
So the answer is: you can't do that. Create a new assembly for the parts that are UI based.
I hope isn't a stupid question...
Is possible to load a no silverlight assembly into a silverlight project without using a COM object?
Thanks in advance.
You can use the Portable Class Library (PCL)
Use this project to write and build portable assemblies that work
without modification on multiple platforms, such as Windows 7, Windows
8, Silverlight, Windows Phone, and Xbox 360. For example, you can
create classes that contain shared business logic for desktop apps,
Windows Store apps, and mobile apps, and you can then reference those
classes from your apps.
The Portable Class Library project supports a subset of assemblies
from the .NET Framework, Silverlight, .NET for Windows Store apps,
Windows Phone, and Xbox 360, and provides a Visual Studio template
that you can use to build assemblies that run without modification on
these platforms. If you don't use a Portable Class Library project,
you must target a single app type, and then manually rework the class
library for other app types. With the Portable Class Library project,
you can reduce the time and costs of developing and testing code by
building portable assemblies that are shared across apps for different
devices.
Also, Microsoft's Scott Hanselman has written a few articles about the PCL, this one should be a good starting point to find the resources you need to get started: Cross-Platform Portable Class Libraries with .NET are Happening
While dealing with creating a Portable Class Library out of current code for a project, some workarounds are fairly obvious and some are problematic.
System.IO.Directory is non-PCL and I still need to be able to create a directory before creating files inside them.
How do you create a folder in C# without being able to call Directory.CreateDirectory(..)?
There is no built-in file and directory I/O support in PCL, since this functionality differs from platform to platform. However, to circumvent this issue you could reference PCLStorage in your portable class library project.
PCLStorage provides a portable abstraction layer library for file and directory I/O that you would reference in your portable class library. In your platform-specific application implementation, you would incorporate the corresponding implementation library of this abstraction layer.
PCLStorage is applicable to .NET Framework 4 and higher, Silverlight 4 and higher, Windows Phone 7.5 and higher, and Windows Store apps. It relies on async and await, which means that it is dependent on the BCL Async package when used e.g. with .NET 4, Silverlight and Windows Phone 7.5.
You might also want to have a look at the MvvmCross File plug-in. MvvmCross is portable "by nature" and the File plug-in provides relevant file and directory I/O functionality as synchronous methods. MvvmCross portable libraries are currently applicable to .NET Framework 4.5, Silverlight 4 and higher, Windows Phone 7.5 and higher, Windows Store apps, Xamarin.iOS and Xamarin.Android.
I don't know if maybe I have something installed incorrectly, but having made a C# Portable Class Library targeting .NET for Windows Store apps, .NET Framework 4.5, Silverlight 4 and higher, Windows Phone 7 and higher, I'm getting errors that System.Tuple is missing.
How could this be?
Tuple[<...>] doesn't exist in Windows Phone 7, so you can't use it if you are targeting that platform.
I've just validated, and if you create a PCL targeting:
.NET for Windows Store apps
.NET Framework 4.5
Silverlight 4 and higher
but not "Windows Phone 7 and higher", then it works fine and you can use Tuple[<...>].
For completeness, it also doesn't exist if you include Xbox 360.
The Microsoft.Bcl NuGet package includes Tuple types for Windows Phone 7.5, and will allow you to use them in a Portable Class Library targeting WP7.5, SL4, Windows Store apps, and .NET 4 (or higher platforms).
In general, full list of portable APIs and what platforms they are available on is here: http://sdrv.ms/OVdfNc. However, that spreadsheet doesn't include information about what types we've added support for via external means (such as the Microsoft.Bcl package).