From efc97771e1c30cc68b3ac88c64d58e4bd1be8bef Mon Sep 17 00:00:00 2001 From: jfrijters Date: Tue, 18 May 2010 06:49:38 +0000 Subject: [PATCH] Hook AssemblyResolve.Warning event to suppress the HigherVersion event, as we don't care about that one in this scenario. Added check to avoid running on ourself, because it results in an exception. --- ikvmstub/ikvmstub.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ikvmstub/ikvmstub.cs b/ikvmstub/ikvmstub.cs index 34347075..a066da10 100644 --- a/ikvmstub/ikvmstub.cs +++ b/ikvmstub/ikvmstub.cs @@ -102,8 +102,9 @@ static class NetExp // This allows "ikvmstub -nostdlib \...\mscorlib.dll" to work. references.Add(assemblyNameOrPath); } + StaticCompiler.Resolver.Warning += new AssemblyResolver.WarningEvent(Resolver_Warning); StaticCompiler.Resolver.Init(StaticCompiler.Universe, nostdlib, references, libpaths); - StaticCompiler.LoadFile(typeof(NetExp).Assembly.Location); + Assembly ikvmstubAssembly = StaticCompiler.LoadFile(typeof(NetExp).Assembly.Location); Dictionary cache = new Dictionary(); foreach (string reference in references) { @@ -141,6 +142,13 @@ static class NetExp { if (AttributeHelper.IsJavaModule(assembly.ManifestModule)) { + if (assembly == ikvmstubAssembly) + { + // we'll crash if we allow this, because CompiledTypeWrapper cannot handle .NET types that use features that we don't expose in Java + // (e.g. the ReadPackedInteger(ref int position) method in LineNumberTableAttribute) + Console.Error.WriteLine("Error: you cannot run ikvmstub on itself"); + return 1; + } Console.Error.WriteLine("Warning: Running ikvmstub on ikvmc compiled assemblies is not supported."); } try @@ -202,6 +210,14 @@ static class NetExp return rc; } + static void Resolver_Warning(AssemblyResolver.WarningId warning, string message, string[] parameters) + { + if (warning != AssemblyResolver.WarningId.HigherVersion) + { + Console.Error.WriteLine("Warning: " + message, parameters); + } + } + private static string GetVersionAndCopyrightInfo() { System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly();