diff --git a/src/dll/util.c b/src/dll/util.c index 0f2f8a8d..cd36df5c 100644 --- a/src/dll/util.c +++ b/src/dll/util.c @@ -175,6 +175,8 @@ FSP_API NTSTATUS FspVersion(PUINT32 PVersion) * Two threads competing to read the version will read * the same value from the Version resource. */ + *PVersion = 0; + extern HINSTANCE DllInstance; WCHAR ModuleFileName[MAX_PATH]; PVOID VersionInfo; diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index 3577bc21..5ce3935e 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -18,6 +18,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Runtime.InteropServices; using System.Security; using System.Security.AccessControl; @@ -850,6 +851,17 @@ namespace Fsp.Interop FspWin32FromNtStatus = GetEntryPoint(Module); FspDebugLogSetHandle = GetEntryPoint(Module); } + private static void CheckVersion() + { + FileVersionInfo Info; + UInt32 Version = 0, VersionMajor, VersionMinor; + Info = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); + FspVersion(out Version); VersionMajor = Version >> 16; VersionMinor = Version & 0xFFFF; + if (Info.FileMajorPart != VersionMajor || Info.FileMinorPart > VersionMinor) + throw new TypeLoadException(String.Format( + "incorrect dll version (need {0}.{1}, have {2}.{3})", + Info.FileMajorPart, Info.FileMinorPart, VersionMajor, VersionMinor)); + } static Api() { #if false //DEBUG @@ -857,6 +869,7 @@ namespace Fsp.Interop Debugger.Break(); #endif LoadProto(LoadDll()); + CheckVersion(); } [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]