From e8cee58b48829220885efa2ccb8a662fcb259eeb Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Fri, 8 Jan 2021 11:32:32 +0100 Subject: [PATCH] fix #1899 --- NETGenerator/CodeGenerator.cs | 2 +- NETGenerator/NETGenerator.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/NETGenerator/CodeGenerator.cs b/NETGenerator/CodeGenerator.cs index 92a05febd..440f7988c 100644 --- a/NETGenerator/CodeGenerator.cs +++ b/NETGenerator/CodeGenerator.cs @@ -25,7 +25,7 @@ namespace PascalABCCompiler.CodeGenerators NETGenerator.CompilerOptions options, Hashtable StandartDirectories, string[] ResourceFiles) { il_converter = new NETGenerator.ILConverter(StandartDirectories); - il_converter.ConvertFromTree(ProgramTree,TargetFileName,SourceFileName,options,ResourceFiles); + il_converter.ConvertFromTree(ProgramTree, TargetFileName, SourceFileName, options, ResourceFiles); } public void Reset() diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 1bbdf2d05..4e968b665 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -175,9 +175,11 @@ namespace PascalABCCompiler.NETGenerator private bool has_dereferences = false; private bool safe_block = false; private int cur_line = 0; + private bool tried_with_unmanaged_resources = false; private ISymbolDocumentWriter new_doc; private List pinned_variables = new List(); private bool pabc_rtl_converted = false; + bool has_unmanaged_resources = false; private void CheckLocation(SemanticTree.ILocation Location) { @@ -571,18 +573,20 @@ namespace PascalABCCompiler.NETGenerator ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run, dir);//определяем сборку else ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.Save, dir);//определяем сборку - + //int nn = ad.GetAssemblies().Length; if (options.NeedDefineVersionInfo) { ab.DefineVersionInfoResource(options.Product, options.ProductVersion, options.Company, options.Copyright, options.TradeMark); + has_unmanaged_resources = true; } if (options.MainResourceFileName != null) { try { ab.DefineUnmanagedResource(options.MainResourceFileName); + has_unmanaged_resources = true; } catch { @@ -594,6 +598,7 @@ namespace PascalABCCompiler.NETGenerator try { ab.DefineUnmanagedResource(options.MainResourceData); + has_unmanaged_resources = true; } catch { @@ -1091,7 +1096,11 @@ namespace PascalABCCompiler.NETGenerator catch (System.IO.IOException e) { if (tries < num_try_save) + { + if (has_unmanaged_resources) + throw new TreeConverter.SaveAssemblyError(e.Message, new TreeRealization.location(0, 0, 0, 0, new TreeRealization.document(SourceFileName))); tries++; + } else throw new TreeConverter.SaveAssemblyError(e.Message, new TreeRealization.location(0, 0, 0, 0, new TreeRealization.document(SourceFileName))); }