[mapguide-commits] r10281 - in branches/4.0/MgDev: . Bindings Bindings/src/Managed/DotNet/Common Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/build Bindings/src/Tools/ClassMapGen Bindings/src/Tools/ClassMapGen/Data/Templates Portable/MgPortable/System
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Mon Nov 9 04:43:16 PST 2026
Author: jng
Date: 2026-11-09 04:43:15 -0800 (Mon, 09 Nov 2026)
New Revision: 10281
Modified:
branches/4.0/MgDev/Bindings/setup_linux_native_libs.cmd
branches/4.0/MgDev/Bindings/src/Managed/DotNet/Common/MgClassMap.cs
branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/OSGeo.MapGuide.Portable.csproj
branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/build/OSGeo.MapGuide.Portable.targets
branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Data/Templates/dotnet.txt
branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Program.cs
branches/4.0/MgDev/CMakeLists.txt
branches/4.0/MgDev/Portable/MgPortable/System/PlatformInit.cpp
Log:
#2897: Run a packaged MgPortable application from its own directory
A console application that consumes OSGeo.MapGuide.Portable could not be started from its project
directory, and the two reasons for that were both in the package rather than in the application.
The package staged the FDO install twice. Side-by-side with FDO/, where the targets put the whole
tree for FdoPath, they also copied tools/FDO/linux/lib64/*.* - which MSBuild reads as "every file"
- and lib64/com/** into the application's output directory, so the providers, providers.xml,
libgdal, libxerces, libxalan and com/ all landed beside the executable as well. That only ever
helped an application built with a runtime identifier, where NuGet flattens the native assets into
that directory and $ORIGIN finds them; with no runtime identifier the MapGuide libraries stay in
runtimes/<rid>/native, where neither $ORIGIN/../../lib64 nor $ORIGIN/../fdo/lib64 resolves
FDO/lib64, so the flat copies were unreachable too and the failure surfaced as a
DllNotFoundException naming PortableUnmanagedApi.so. The libraries' own RPATH now names the package
layout, so nothing has to be copied out of FDO: $ORIGIN/FDO/lib64 for the application directory and
$ORIGIN/../../../FDO/lib64 for runtimes/<rid>/native. The libFDO.so link that FdoPath needs points
at the versioned library beside it instead of at a flattened copy, and FDO still finds providers.xml,
the providers and their com data beside the libFDO loaded that way.
The first P/Invoke could also fail with "Could not resolve .net type for this unmanaged pointer. The
unmanaged pointer reported a class ID of: 1515" instead of reporting the exception that was thrown.
MgClassMap is compiled into every wrapper and registered a class id only for the assemblies that
were already in the AppDomain, and .NET loads an assembly on first use: an application whose first
call is MgPortablePlatform.Initialize has never touched OSGeo.MapGuide.Foundation, so the class id
of the MgException its native side throws was missing from the map. Foundation and Geometry, the two
assemblies every binding carries, are now loaded by simple name when the map is built. Everything
downstream of them is still registered only when it is already loaded, because loading it to
enumerate class ids would pull a server binding into a portable application, or the portable API
into a MapGuide application, and a proxy type from an optional assembly can only be needed after the
application has used that assembly.
Finally, Platform.ini describes the layout beside the application - Resources/, Schema/, FDO/,
Dictionaries/ and the repositories - but those paths were resolved against the process working
directory. `dotnet run` starts an application in its project directory, not in its output directory,
so Initialize failed on the schema directory it could not find. MgPortablePlatform::Initialize now
resolves every path-valued property the configuration carries against the configuration file's own
directory, before anything reads it, and writes the resolved values back into MgConfiguration so the
services that read it later get the same absolute paths. An absolute value is left alone, a property
the file does not carry resolves from the default its consumers fall back to, and an empty default
stays empty.
- CMakeLists.txt: add $ORIGIN/FDO/lib64 and $ORIGIN/../../../FDO/lib64 to
MG_PORTABLE_INSTALL_RPATH, alongside the install-tree and tarball entries.
- OSGeo.MapGuide.Portable.targets: drop the lib64/*.* and lib64/com/** staging, so FDO is copied
only into FDO/; create FDO/lib64/libFDO.so as a link to the versioned library in that directory.
- OSGeo.MapGuide.Portable.csproj, setup_linux_native_libs.cmd: describe where the FDO install and
Platform.ini are packed and why the RPATH has to name it.
- ClassMapGen/Program.cs, ClassMapGen/Data/Templates/dotnet.txt, Common/MgClassMap.cs: emit and
carry IsAssemblyAvailable(name, loadIfNeeded), with Foundation and Geometry as the only modules
that ask for the assembly to be loaded.
- Portable/MgPortable/System/PlatformInit.cpp: resolve the configuration's paths against the
configuration file's directory in Initialize, before the resources, log manager and service
factory read them.
Verified with a Release mapguide_rel.bat -w=portable build (0 errors) and a net10.0 console
application that references OSGeo.MapGuide.Portable and nothing else: dotnet run from its project
directory and the built assembly started with C:\ as the working directory both initialize, resolve
EPSG:4326 through the packaged Dictionaries, and load only Foundation, Geometry and Portable -
MapGuideCommon and Web are never loaded. The same call with a bare "Platform.ini" that is not in the
working directory now throws the MgException from MgConfiguration.LoadConfiguration instead of the
class-map error, and an application that references only OSGeo.MapGuide.Geometry uses
MgCoordinateSystemFactory without Portable being loaded. Packing the package and building and
publishing a consumer with OS=Unix produces an output directory with no FDO files in it, FDO/ holding
lib64, nls, providers.xml and com/, Platform.ini beside the application and FDO/lib64/libFDO.so a
link to libFDO-4.2.0.so. The Windows branch of the targets is unchanged.
The two new RPATH entries take effect when the portable tarball is rebuilt; loading the packaged FDO
tree on Linux was not exercised here.
Modified: branches/4.0/MgDev/Bindings/setup_linux_native_libs.cmd
===================================================================
--- branches/4.0/MgDev/Bindings/setup_linux_native_libs.cmd 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/setup_linux_native_libs.cmd 2026-11-09 12:43:15 UTC (rev 10281)
@@ -67,9 +67,11 @@
perl -i.bak -pe "s#^FdoPath\s*=.*#FdoPath = FDO/lib64/#" "%PORTABLE_DIR%\config\linux\Platform.ini"
if exist "%PORTABLE_DIR%\config\linux\Platform.ini.bak" del /Q "%PORTABLE_DIR%\config\linux\Platform.ini.bak"
rem The libraries MgPortable is linked against have to travel as runtime assets, because the
-rem loader resolves them through the $ORIGIN RUNPATH of PortableUnmanagedApi.so as soon as the
-rem first call binds that library - before MgPortablePlatform::Initialize can honour FdoPath. Only
-rem the ones no other package carries are staged here, though: libMgFoundation, libMgMdfModel,
+rem loader resolves them through the $ORIGIN RPATH of PortableUnmanagedApi.so as soon as the
+rem first call binds that library - before MgPortablePlatform::Initialize can honour FdoPath. The
+rem FDO install does not travel beside them: it is packed as the FDO\linux tree and the consuming
+rem application stages it in FDO/lib64, which the same RPATH names. Only the libraries no other
+rem package carries are staged here, though: libMgFoundation, libMgMdfModel,
rem libACE.so.6.2.6 and libxerces-c-3.1.so come with OSGeo.MapGuide.Foundation, libMgPlatformBase
rem and libMgMdfParser with OSGeo.MapGuide.PlatformBase, and libMgGeometry with
rem OSGeo.MapGuide.Geometry - all three are dependencies of this package, and NuGet stages every
Modified: branches/4.0/MgDev/Bindings/src/Managed/DotNet/Common/MgClassMap.cs
===================================================================
--- branches/4.0/MgDev/Bindings/src/Managed/DotNet/Common/MgClassMap.cs 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/src/Managed/DotNet/Common/MgClassMap.cs 2026-11-09 12:43:15 UTC (rev 10281)
@@ -29,7 +29,7 @@
var classNameMap = new Dictionary<int, string>();
nameClassMap = new Dictionary<string, int>();
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.Foundation")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.Foundation", true)) {
classIdCtorMap[1000] = TryResolveConstructor("OSGeo.MapGuide.MgDisposableCollection");
classIdCtorMap[1002] = TryResolveConstructor("OSGeo.MapGuide.MgPropertyCollection");
classIdCtorMap[1003] = TryResolveConstructor("OSGeo.MapGuide.MgStringCollection");
@@ -46,7 +46,7 @@
classIdCtorMap[2251] = TryResolveConstructor("OSGeo.MapGuide.MgDisposable");
classIdCtorMap[2252] = TryResolveConstructor("OSGeo.MapGuide.MgObject");
}
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.Geometry")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.Geometry", true)) {
classIdCtorMap[20000] = TryResolveConstructor("OSGeo.MapGuide.MgPoint");
classIdCtorMap[20001] = TryResolveConstructor("OSGeo.MapGuide.MgEnvelope");
classIdCtorMap[20002] = TryResolveConstructor("OSGeo.MapGuide.MgGeometryFactory");
@@ -138,7 +138,7 @@
classIdCtorMap[20545] = TryResolveConstructor("OSGeo.MapGuide.MgCoordinateSystemGeodeticTransformGridFile");
classIdCtorMap[20546] = TryResolveConstructor("OSGeo.MapGuide.MgCoordinateSystemGeodeticStandaloneTransformDefParams");
}
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.PlatformBase")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.PlatformBase", false)) {
classIdCtorMap[10000] = TryResolveConstructor("OSGeo.MapGuide.MgIntCollection");
classIdCtorMap[10001] = TryResolveConstructor("OSGeo.MapGuide.MgPropertyDefinitionCollection");
classIdCtorMap[10003] = TryResolveConstructor("OSGeo.MapGuide.MgStringPropertyCollection");
@@ -199,7 +199,7 @@
classIdCtorMap[11501] = TryResolveConstructor("OSGeo.MapGuide.MgResourceService");
classIdCtorMap[11526] = TryResolveConstructor("OSGeo.MapGuide.MgResource");
}
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.MapGuideCommon")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.MapGuideCommon", false)) {
classIdCtorMap[30500] = TryResolveConstructor("OSGeo.MapGuide.MgMap");
classIdCtorMap[30501] = TryResolveConstructor("OSGeo.MapGuide.MgLayer");
classIdCtorMap[30502] = TryResolveConstructor("OSGeo.MapGuide.MgSelection");
@@ -224,7 +224,7 @@
classIdCtorMap[31300] = TryResolveConstructor("OSGeo.MapGuide.MgKmlService");
classIdCtorMap[31400] = TryResolveConstructor("OSGeo.MapGuide.MgProfilingService");
}
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.Web")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.Web", false)) {
classIdCtorMap[50000] = TryResolveConstructor("OSGeo.MapGuide.MgWebCommand");
classIdCtorMap[50001] = TryResolveConstructor("OSGeo.MapGuide.MgWebUiTargetCommand");
classIdCtorMap[50002] = TryResolveConstructor("OSGeo.MapGuide.MgWebSearchCommand");
@@ -264,7 +264,7 @@
// UGLY: It is mildly annoying/hackish that we are incorporating class ids for a library not known
// to the majority of the library wrappers that reference this file, but it would be more complicated
// work to achieve pure physical MgClassMap/assembly separation.
- if (HasAssemblyInAppDomain("OSGeo.MapGuide.Portable")) {
+ if (IsAssemblyAvailable("OSGeo.MapGuide.Portable", false)) {
classIdCtorMap[60500] = TryResolveConstructor("OSGeo.MapGuide.MgPortableMap");
classIdCtorMap[60501] = TryResolveConstructor("OSGeo.MapGuide.MgPortableLayer");
classIdCtorMap[60502] = TryResolveConstructor("OSGeo.MapGuide.MgPortableSelection");
@@ -313,13 +313,22 @@
return classIdCtorMap.ContainsKey(classId) ? classIdCtorMap[classId] : null;
}
- static bool HasAssemblyInAppDomain(string assemblyName)
+ // A class id can only be registered from an assembly that is available. For the two
+ // assemblies every binding carries, "available" has to mean "can be loaded" and not "has
+ // already been loaded": .NET loads an assembly on first use, so the first P/Invoke can throw
+ // a native exception whose proxy type lives in one that nothing has touched yet - a console
+ // application whose first call is MgPortablePlatform.Initialize does exactly that - and the
+ // class id of that exception would then be missing, hiding it behind "Could not resolve .net
+ // type for this unmanaged pointer". Everything downstream of those two is optional and is
+ // registered only when it is already loaded: loading it to enumerate its class ids would pull
+ // a server binding into a portable application, or the portable API into a MapGuide one, and
+ // an application can only need a proxy type from an assembly it has already used.
+ static bool IsAssemblyAvailable(string assemblyName, bool loadIfNeeded)
{
#if MONOLITHIC_ASSEMBLY
return true;
#else
- var assemblies = global::System.AppDomain.CurrentDomain.GetAssemblies();
- foreach (var assem in assemblies)
+ foreach (var assem in global::System.AppDomain.CurrentDomain.GetAssemblies())
{
var asmName = new global::System.Reflection.AssemblyName(assem.FullName);
if (asmName.Name == assemblyName)
@@ -327,7 +336,24 @@
return true;
}
}
- return false;
+
+ if (!loadIfNeeded)
+ {
+ return false;
+ }
+
+ try
+ {
+ // The assembly is a dependency of the one being used, so its simple name resolves
+ // through the application's dependency graph. Nothing may escape: this runs from the
+ // exception callback into native code.
+ global::System.Reflection.Assembly.Load(new global::System.Reflection.AssemblyName(assemblyName));
+ return true;
+ }
+ catch (global::System.Exception)
+ {
+ return false;
+ }
#endif
}
Modified: branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/OSGeo.MapGuide.Portable.csproj
===================================================================
--- branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/OSGeo.MapGuide.Portable.csproj 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/OSGeo.MapGuide.Portable.csproj 2026-11-09 12:43:15 UTC (rev 10281)
@@ -31,9 +31,10 @@
<ItemGroup>
<Content Include="build/**" PackagePath="%(Identity)" />
- <!-- Everything staged under runtimes/ is a runtime asset: the Linux tree carries the tarball's
- own layout (lib64/, fdo/lib64/, fdo/nls/ and Platform.ini), and the message catalogues it
- holds are .cat files, so the glob cannot be limited to the library extensions. -->
+ <!-- Everything staged under runtimes/ is a runtime asset: each platform's tree is one flat set
+ of shared libraries beside a readme, so the glob cannot be limited to a naming convention.
+ The FDO install and Platform.ini are package content rather than runtime assets, because
+ they have to keep their directory; build/OSGeo.MapGuide.Portable.targets stages them. -->
<Content Include="runtimes/**/*" PackagePath="%(Identity)" />
</ItemGroup>
Modified: branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/build/OSGeo.MapGuide.Portable.targets
===================================================================
--- branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/build/OSGeo.MapGuide.Portable.targets 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/src/Managed/DotNet/OSGeo.MapGuide.Portable/build/OSGeo.MapGuide.Portable.targets 2026-11-09 12:43:15 UTC (rev 10281)
@@ -16,8 +16,6 @@
<ItemGroup Condition=" '$(OS)' != 'Windows_NT' ">
<MgPortableLinuxPlatformIni Include="$(MSBuildThisFileDirectory)..\tools\config\linux\Platform.ini" />
<MgPortableLinuxFdoFile Include="$(MSBuildThisFileDirectory)..\tools\FDO\linux\**\*" />
- <MgPortableLinuxFdoLibFile Include="$(MSBuildThisFileDirectory)..\tools\FDO\linux\lib64\*.*" />
- <MgPortableLinuxFdoComFile Include="$(MSBuildThisFileDirectory)..\tools\FDO\linux\lib64\com\**\*" />
<MgPortableLinuxFdoRealLibFile Include="$(MSBuildThisFileDirectory)..\tools\FDO\linux\lib64\libFDO-*.so" />
</ItemGroup>
@@ -31,31 +29,29 @@
a platform, so neither of the two FDO installs the package carries can be declared as one: each
is packed as plain package content and the one belonging to the consuming platform is staged
here. Both land in FDO next to the application, and the platform's Platform.ini is placed beside
- the application as well, so the platform split exists only inside the package. On Linux the
- libraries are staged into the output root too, with the com directory beside them: the loader
- resolves libFDO and libExpressionEngine through the $ORIGIN RUNPATH of PortableUnmanagedApi.so
- as soon as the first call binds that library, before MgPortablePlatform::Initialize honours
- FdoPath, and FDO looks for providers.xml and its providers beside the libFDO loaded that way.
+ the application as well, so the platform split exists only inside the package. Nothing else is
+ copied into the output directory root: the loader reaches the FDO libraries through the FDO
+ entries in the MapGuide libraries' own RPATH (MG_PORTABLE_INSTALL_RPATH in the CMake build),
+ which resolve FDO/lib64 both beside the application and three levels above the package's
+ runtimes/<rid>/native directory. That covers libFDO and libExpressionEngine as soon as the first
+ call binds PortableUnmanagedApi.so, before MgPortablePlatform::Initialize honours FdoPath. FDO
+ finds its providers.xml, its providers and their com data beside the libFDO loaded that way.
-->
<Target Name="StageLinuxFdoForBuild" AfterTargets="Build" Condition=" '@(MgPortableLinuxFdoFile)' != '' ">
<Copy SourceFiles="@(MgPortableLinuxFdoFile)" DestinationFiles="@(MgPortableLinuxFdoFile->'$(OutDir)FDO/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
- <Copy SourceFiles="@(MgPortableLinuxFdoLibFile)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
- <Copy SourceFiles="@(MgPortableLinuxFdoComFile)" DestinationFiles="@(MgPortableLinuxFdoComFile->'$(OutDir)com/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(MgPortableLinuxPlatformIni)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
<!-- The tarball ships no links (NuGet would copy them as duplicates), and FdoPath is
FDO/lib64. MgPortablePlatform::Initialize() dlopens <FdoPath>libFDO.so; a file there
- would be a second FDO instance, because the flat libFDO has already been loaded
- through the $ORIGIN RUNPATH of PortableUnmanagedApi.so, and two instances crash when
- their static destructors run. Link the name to that already-loaded flat library. -->
- <Exec Command="ln -sfn ../../%(MgPortableLinuxFdoRealLibFile.Filename)%(MgPortableLinuxFdoRealLibFile.Extension) "$(OutDir)FDO/lib64/libFDO.so"" Condition=" '@(MgPortableLinuxFdoRealLibFile)' != '' " />
+ would be a second FDO instance, because the versioned library beside it has already
+ been loaded through the RPATH of PortableUnmanagedApi.so, and two instances crash
+ when their static destructors run. Link the name to that library. -->
+ <Exec Command="ln -sfn %(MgPortableLinuxFdoRealLibFile.Filename)%(MgPortableLinuxFdoRealLibFile.Extension) "$(OutDir)FDO/lib64/libFDO.so"" Condition=" '@(MgPortableLinuxFdoRealLibFile)' != '' " />
</Target>
<Target Name="StageLinuxFdoForPublish" AfterTargets="Publish" Condition=" '@(MgPortableLinuxFdoFile)' != '' ">
<Copy SourceFiles="@(MgPortableLinuxFdoFile)" DestinationFiles="@(MgPortableLinuxFdoFile->'$(PublishDir)FDO/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
- <Copy SourceFiles="@(MgPortableLinuxFdoLibFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
- <Copy SourceFiles="@(MgPortableLinuxFdoComFile)" DestinationFiles="@(MgPortableLinuxFdoComFile->'$(PublishDir)com/%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(MgPortableLinuxPlatformIni)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
- <Exec Command="ln -sfn ../../%(MgPortableLinuxFdoRealLibFile.Filename)%(MgPortableLinuxFdoRealLibFile.Extension) "$(PublishDir)FDO/lib64/libFDO.so"" Condition=" '@(MgPortableLinuxFdoRealLibFile)' != '' " />
+ <Exec Command="ln -sfn %(MgPortableLinuxFdoRealLibFile.Filename)%(MgPortableLinuxFdoRealLibFile.Extension) "$(PublishDir)FDO/lib64/libFDO.so"" Condition=" '@(MgPortableLinuxFdoRealLibFile)' != '' " />
</Target>
<Target Name="StageWindowsFdoForBuild" AfterTargets="Build" Condition=" '@(MgPortableWindowsFdoFile)' != '' ">
Modified: branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Data/Templates/dotnet.txt
===================================================================
--- branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Data/Templates/dotnet.txt 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Data/Templates/dotnet.txt 2026-11-09 12:43:15 UTC (rev 10281)
@@ -57,13 +57,22 @@
return classIdCtorMap.ContainsKey(classId) ? classIdCtorMap[classId] : null;
}
- static bool HasAssemblyInAppDomain(string assemblyName)
+ // A class id can only be registered from an assembly that is available. For the two
+ // assemblies every binding carries, "available" has to mean "can be loaded" and not "has
+ // already been loaded": .NET loads an assembly on first use, so the first P/Invoke can throw
+ // a native exception whose proxy type lives in one that nothing has touched yet - a console
+ // application whose first call is MgPortablePlatform.Initialize does exactly that - and the
+ // class id of that exception would then be missing, hiding it behind "Could not resolve .net
+ // type for this unmanaged pointer". Everything downstream of those two is optional and is
+ // registered only when it is already loaded: loading it to enumerate its class ids would pull
+ // a server binding into a portable application, or the portable API into a MapGuide one, and
+ // an application can only need a proxy type from an assembly it has already used.
+ static bool IsAssemblyAvailable(string assemblyName, bool loadIfNeeded)
{
#if MONOLITHIC_ASSEMBLY
return true;
#else
- var assemblies = global::System.AppDomain.CurrentDomain.GetAssemblies();
- foreach (var assem in assemblies)
+ foreach (var assem in global::System.AppDomain.CurrentDomain.GetAssemblies())
{
var asmName = new global::System.Reflection.AssemblyName(assem.FullName);
if (asmName.Name == assemblyName)
@@ -71,7 +80,24 @@
return true;
}
}
- return false;
+
+ if (!loadIfNeeded)
+ {
+ return false;
+ }
+
+ try
+ {
+ // The assembly is a dependency of the one being used, so its simple name resolves
+ // through the application's dependency graph. Nothing may escape: this runs from the
+ // exception callback into native code.
+ global::System.Reflection.Assembly.Load(new global::System.Reflection.AssemblyName(assemblyName));
+ return true;
+ }
+ catch (global::System.Exception)
+ {
+ return false;
+ }
#endif
}
Modified: branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Program.cs
===================================================================
--- branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Program.cs 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Bindings/src/Tools/ClassMapGen/Program.cs 2026-11-09 12:43:15 UTC (rev 10281)
@@ -133,6 +133,14 @@
var dotNetClassMaps = new StringBuilder();
+ // The two assemblies every binding carries. They are the only ones whose class ids have to
+ // be registered before the application has used them, because a native call can throw an
+ // exception from either before anything has resolved one of their types. Everything
+ // downstream of them is an optional library - the server bindings for a MapGuide
+ // application, the portable API for a portable one - and must not be loaded merely to
+ // enumerate the class ids it would contribute.
+ var requiredDotNetModules = new HashSet<string> { "Foundation", "Geometry" };
+
//.net
foreach (var mod in clsMap.Modules)
{
@@ -144,7 +152,8 @@
// work to achieve pure physical MgClassMap/assembly separation.");
}
- dotNetClassMaps.AppendLine($"{DOTNET_INDENT}if (HasAssemblyInAppDomain(\"OSGeo.MapGuide.{mod.Name}\")) {{");
+ bool loadIfNeeded = requiredDotNetModules.Contains(mod.Name);
+ dotNetClassMaps.AppendLine($"{DOTNET_INDENT}if (IsAssemblyAvailable(\"OSGeo.MapGuide.{mod.Name}\", {loadIfNeeded.ToString().ToLowerInvariant()})) {{");
foreach (var kvp in mod.Classes)
{
Modified: branches/4.0/MgDev/CMakeLists.txt
===================================================================
--- branches/4.0/MgDev/CMakeLists.txt 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/CMakeLists.txt 2026-11-09 12:43:15 UTC (rev 10281)
@@ -104,11 +104,16 @@
option(WITH_PORTABLE "Build MgPortable (the portable MapGuide API)" OFF)
-# Runtime search path for the libraries MgPortable and its dependants install. Two layouts have to
+# Runtime search path for the libraries MgPortable and its dependants install. Four layouts have to
# work: the install tree, where MgPortable's libraries sit in <prefix>/portable/lib64 and the common
-# ones in <prefix>/lib64, and the MgPortable tarball, which flattens the portable libraries into
-# lib64/ and keeps the whole FDO install in a sibling fdo/lib64 so it travels as one subtree.
-set(MG_PORTABLE_INSTALL_RPATH "$ORIGIN:$ORIGIN/../../lib64:$ORIGIN/../fdo/lib64")
+# ones in <prefix>/lib64; the MgPortable tarball, which flattens the portable libraries into lib64/
+# and keeps the whole FDO install in a sibling fdo/lib64 so it travels as one subtree; the NuGet
+# package, which flattens the portable libraries into the application's directory and stages the FDO
+# install in FDO/lib64 beneath it; and the same package in an application that has no runtime
+# identifier, where the portable libraries stay in runtimes/<rid>/native and FDO is three levels up.
+# Without the FDO entries a consumer of the package cannot resolve libFDO or libExpressionEngine,
+# and both would have to be copied beside the application as well.
+set(MG_PORTABLE_INSTALL_RPATH "$ORIGIN:$ORIGIN/FDO/lib64:$ORIGIN/../../../FDO/lib64:$ORIGIN/../../lib64:$ORIGIN/../fdo/lib64")
set(MG_AUTO_GENERATED_HEADER_DIR "${CMAKE_CURRENT_BINARY_DIR}/IncludeAutogenerated")
set(MG_UNIT_TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/UnitTest/TestData")
Modified: branches/4.0/MgDev/Portable/MgPortable/System/PlatformInit.cpp
===================================================================
--- branches/4.0/MgDev/Portable/MgPortable/System/PlatformInit.cpp 2026-11-09 08:44:32 UTC (rev 10280)
+++ branches/4.0/MgDev/Portable/MgPortable/System/PlatformInit.cpp 2026-11-09 12:43:15 UTC (rev 10281)
@@ -21,6 +21,93 @@
#include "Services/Rendering/MappingUtil.h"
#include "Services/Feature/FdoConnectionPool.h"
+namespace
+{
+
+bool IsAbsolutePath(CREFSTRING path)
+{
+#ifdef _WIN32
+ if (path.size() >= 2 && L':' == path[1])
+ return true; // drive-qualified, C:\...
+ if (path.size() >= 2 && L'\\' == path[0] && L'\\' == path[1])
+ return true; // UNC, \\server\share
+ return !path.empty() && (L'\\' == path[0] || L'/' == path[0]);
+#else
+ return !path.empty() && L'/' == path[0];
+#endif
+}
+
+// Resolves one path-valued property against the configuration file's directory. A property the file
+// does not carry is resolved from the default its consumers fall back to, so that both descriptions
+// of the layout end up anchored in the same place; an empty default is an optional path and stays
+// empty.
+void ResolvePathProperty(CREFSTRING section, CREFSTRING property, CREFSTRING defaultValue, CREFSTRING configDir)
+{
+ MgConfiguration* pConfiguration = MgConfiguration::GetInstance();
+
+ STRING path;
+ pConfiguration->GetStringValue(section, property, path, defaultValue);
+ if (path.empty() || IsAbsolutePath(path))
+ return;
+
+ Ptr<MgStringProperty> resolvedPath = new MgStringProperty(property, configDir + path);
+ Ptr<MgPropertyCollection> resolvedPaths = new MgPropertyCollection();
+ resolvedPaths->Add(resolvedPath);
+ pConfiguration->SetProperties(section, resolvedPaths);
+}
+
+// Platform.ini is written to sit beside the application, and the paths in it describe that layout:
+// Resources/, Schema/, FDO/, Dictionaries/ and the repositories are all beside the application, not
+// beside whatever directory the process happens to have been started in. Those are not the same
+// directory in general - `dotnet run` starts an application in its project directory - so resolve
+// every path the configuration carries against the configuration file's own directory before
+// anything reads it, which also gives the same paths to the services that read it later.
+void ResolveConfigurationPaths(CREFSTRING configFile)
+{
+ STRING::size_type lastSeparator = configFile.find_last_of(L"/\\");
+ if (STRING::npos == lastSeparator)
+ return; // no directory part: the working directory is the base the paths were written for
+
+ STRING configDir = configFile.substr(0, lastSeparator + 1);
+
+ typedef MgPortableConfigProperties Properties;
+ struct PathProperty
+ {
+ const STRING* section;
+ const STRING* property;
+ const STRING* defaultValue;
+ };
+
+ const PathProperty pathProperties[] =
+ {
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyFdoPath, &Properties::DefaultGeneralPropertyFdoPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyMentorDictionaryPath, &Properties::DefaultGeneralPropertyMentorDictionaryPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyResourcesPath, &Properties::DefaultGeneralPropertyResourcesPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyTempPath, &Properties::DefaultGeneralPropertyTempPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyWfsDocumentPath, &Properties::DefaultGeneralPropertyWfsDocumentPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyWmsDocumentPath, &Properties::DefaultGeneralPropertyWmsDocumentPath },
+ { &Properties::GeneralPropertiesSection, &Properties::GeneralPropertyLogsPath, &Properties::DefaultGeneralPropertyLogsPath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertyLibraryRepositoryPath, &Properties::DefaultResourceServicePropertyLibraryRepositoryPath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertyLibraryResourceDataFilePath, &Properties::DefaultResourceServicePropertyLibraryResourceDataFilePath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertyPackagesPath, &Properties::DefaultResourceServicePropertyPackagesPath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertyResourceSchemaFilePath, &Properties::DefaultResourceServicePropertyResourceSchemaFilePath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertySessionRepositoryPath, &Properties::DefaultResourceServicePropertySessionRepositoryPath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertySessionResourceDataFilePath, &Properties::DefaultResourceServicePropertySessionResourceDataFilePath },
+ { &Properties::ResourceServicePropertiesSection, &Properties::ResourceServicePropertySiteRepositoryPath, &Properties::DefaultResourceServicePropertySiteRepositoryPath },
+ { &Properties::TileServicePropertiesSection, &Properties::TileServicePropertyTileCachePath, &Properties::DefaultTileServicePropertyTileCachePath }
+ };
+
+ for (size_t i = 0; i < sizeof(pathProperties) / sizeof(pathProperties[0]); i++)
+ {
+ ResolvePathProperty(*pathProperties[i].section,
+ *pathProperties[i].property,
+ *pathProperties[i].defaultValue,
+ configDir);
+ }
+}
+
+}
+
bool MgPortablePlatform::sm_init = false;
bool MgPortablePlatform::IsInitialized() { return sm_init; }
@@ -35,6 +122,7 @@
MgConfiguration* pConfiguration = MgConfiguration::GetInstance();
pConfiguration->LoadConfiguration(configFile);
+ ResolveConfigurationPaths(configFile);
// Get the resources path.
STRING resourcesPath;
More information about the mapguide-commits
mailing list