Dear Math.Net users and developers,
I have recently compiled and used the Math.NET library with .NET CompactFramework 2.0 on Windows CE 5 ARM device.
It would be great if the Math.NET library can support CompactFramework as standard in the future.
Initially I used the MathNet.Iridium.dll that was compiled for the normal .NET Framework on the PC.
I came across 2 problems with that:
1. Visual Studio kept redeploying System.dll and System.xml.dll... to the device every time, because the Framework is not exactly the same as on the device.
2. The functions DoubleToInt64Bits and Int64BitsToDouble are not supported in the .NET CF framework, however they are used by the MathNet.Numerics.Number class.
So in order to compile Math.NET for with .NET CompactFramework, the following modifications were carried out before compiling:
In the AssemblyInfo.cs the following lines were removed:
[assembly: System.Net.SocketPermission(SecurityAction.RequestRefuse, Unrestricted=true)]
[assembly: System.Net.WebPermission(SecurityAction.RequestRefuse, Unrestricted=true)]
[assembly: System.Net.DnsPermission(SecurityAction.RequestRefuse, Unrestricted=true)]
[assembly: System.Net.Mail.SmtpPermission(SecurityAction.RequestRefuse, Unrestricted=true)]
[assembly: System.Net.NetworkInformation.NetworkInformationPermission(SecurityAction.RequestRefuse, Unrestricted=true)]
---------------------------------------------------------------------------------------------------------------
The Project file /Sources/Library/Iridium.csproj was modified to use the Compact Framework:
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
<Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
Just to be sure I also added:
<PlatformFamilyName>WindowsCE</PlatformFamilyName>
<PlatformID>04C93F17-0F18-45DE-A0B5-CF4D71136078</PlatformID>
---------------------------------------------------------------------------------------------------------------
A bitconverter needs to be added to the project, since it is not supported in the compact version of the .NET:
use CF64BitConverter.DoubleToInt64Bits in Sources/Library/Number.cs
Code:
using System;
namespace CF64BitConverterLib
{
/// <summary>
/// A supoort class: the purpose is to integrate System.BitConverter
/// methods not presents in .NET Compact Framework.
/// http://nettopologysuite.googlecode.com/svn/tags/v2.0/2008-06-21%20Drop/NetTopologySuite/Utilities/BitConverter.cs
/// </summary>
public class CF64BitConverter
{
public static Int64 DoubleToInt64Bits(Double x)
{
#if UNSAFE
unsafe
{
return *(Int64*)&x;
}
#else
Byte[ bytes = System.BitConverter.GetBytes(x);
Int64 value = System.BitConverter.ToInt64(bytes, 0);
return value;
#endif
}
public static Double Int64BitsToDouble(Int64 x)
{
#if UNSAFE
unsafe
{
return *(Double*)&x;
}
#else
Byte[ bytes = System.BitConverter.GetBytes(x);
Double value = System.BitConverter.ToDouble(bytes, 0);
return value;
#endif
}
}
}
---------------------------------------------------------------------------------------------------------------
greetings,
Joerg Wolf