Exemple #1
0
        void ProcessAssemblies(List <string> assemblies)
        {
            CreateJavaVM(jvmDllPath);

            var readWriteParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                InMemory         = true,
                ReadSymbols      = true,
                ReadWrite        = true,
            };
            var readWriteParametersNoSymbols = new ReaderParameters {
                AssemblyResolver = resolver,
                InMemory         = true,
                ReadSymbols      = false,
                ReadWrite        = true,
            };

            foreach (var assembly in assemblies)
            {
                if (!File.Exists(assembly))
                {
                    Error($"Path '{assembly}' does not exist.");
                    Environment.Exit(1);
                }

                resolver.SearchDirectories.Add(Path.GetDirectoryName(assembly));
                AssemblyDefinition ad;
                try {
                    ad = AssemblyDefinition.ReadAssembly(assembly, readWriteParameters);
                    resolver.AddToCache(ad);
                } catch (Exception) {
                    if (Verbose)
                    {
                        Warning($"Unable to read assembly '{assembly}' with symbols. Retrying to load it without them.");
                    }
                    ad = AssemblyDefinition.ReadAssembly(assembly, readWriteParametersNoSymbols);
                    resolver.AddToCache(ad);
                }

                Extensions.MethodMap.Clear();
            }

            foreach (var assembly in assemblies)
            {
                try {
                    CreateMarshalMethodAssembly(assembly);
                    definedTypes.Clear();
                } catch (Exception e) {
                    Error($"Unable to process assembly '{assembly}'{Environment.NewLine}{e.Message}{Environment.NewLine}{e}");
                    Environment.Exit(1);
                }
            }
        }
Exemple #2
0
        void ProcessAssemblies(List <string> assemblies)
        {
            CreateJavaVM(jvmDllPath);

            var readerParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                InMemory         = true,
                ReadSymbols      = true,
                ReadWrite        = string.IsNullOrEmpty(outDirectory),
            };
            var readerParametersNoSymbols = new ReaderParameters {
                AssemblyResolver = resolver,
                InMemory         = true,
                ReadSymbols      = false,
                ReadWrite        = string.IsNullOrEmpty(outDirectory),
            };

            foreach (var r in references)
            {
                try {
                    Assembly.LoadFile(Path.GetFullPath(r));
                } catch (Exception) {
                    ErrorAndExit(Message.ErrorUnableToPreloadReference, r);
                }
                resolver.SearchDirectories.Add(Path.GetDirectoryName(r));
            }

            foreach (var assembly in assemblies)
            {
                if (!File.Exists(assembly))
                {
                    ErrorAndExit(Message.ErrorPathDoesNotExist, assembly);
                }

                resolver.SearchDirectories.Add(Path.GetDirectoryName(assembly));
                AssemblyDefinition ad;
                try {
                    ad = AssemblyDefinition.ReadAssembly(assembly, readerParameters);
                    resolver.AddToCache(ad);
                } catch (Exception) {
                    if (Verbose)
                    {
                        Information($"Unable to read assembly '{assembly}' with symbols. Retrying to load it without them.");
                    }

                    ad = AssemblyDefinition.ReadAssembly(assembly, readerParametersNoSymbols);
                    resolver.AddToCache(ad);
                }

                Extensions.MethodMap.Clear();
            }

            foreach (var assembly in assemblies)
            {
                try {
                    CreateMarshalMethodAssembly(assembly);
                    definedTypes.Clear();
                } catch (Exception e) {
                    ErrorAndExit(Message.ErrorUnableToProcessAssembly, assembly, Environment.NewLine, e.Message, e);
                }
            }
        }