After upgrade to 1.14.3, the error occurs. It is unclear whether the problem also occurs with 1.14.2
Logging the calls with first chance exception handler in place returns:
2020-04-28 17:55:53: WIX GUID generation seed 'Component.INSTALLDIR.samples.EmptyDirectory' results in hash by integer -682.106.330 and outcome '545c8cc7-c52b-4aba-9c4f-ebec0f525049'.
2020-04-28 17:55:53: First chance exception handling of type 'NotSupportedException':
2020-04-28 17:55:53: The invoked member is not supported in a dynamic assembly.
2020-04-28 17:55:53: Stack trace:
2020-04-28 17:55:53: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at SIDY.RY.X()
at Invantive.Deploy.Error.CurrentDomain_FirstChanceException(Object sender, FirstChanceExceptionEventArgs e)
at System.Reflection.Emit.InternalAssemblyBuilder.get_Location()
at WixSharp.Extensions.GetLocation(Assembly assembly)
at WixSharp.Utils.<>c__DisplayClass4_0.<OriginalAssemblyFile>b__0(Assembly a)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at WixSharp.Utils.OriginalAssemblyFile(String file)
at WixSharp.Compiler.PackageManagedAsm(String asm, String nativeDll, String[] refAssemblies, String outDir, String configFilePath, Nullable`1 platform, Boolean embeddedUI, String batchFile)
at WixSharp.Compiler.ProcessCustomActions(Project wProject, XElement product)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Project.BuildWxs(OutputType type, String path)
at (Object , OutputType , String )
at SIDY.EXR.X(Object , OutputType , String )
at Invantive.Deploy.ProjectBase.Build()
at Invantive.Producer.Control.Setup.Program.Main() in C:\Users\gle3.WS212\Documents\ws-20.0\Invantive.Control\src\Invantive.Producer.Control.Setup\Program.cs:line 35
2020-04-28 17:55:54: First chance exception handling of type 'FileLoadException':
2020-04-28 17:55:54: API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
2020-04-28 17:55:54: Stack trace:
2020-04-28 17:55:54: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at SIDY.RY.X()
at Invantive.Deploy.Error.CurrentDomain_FirstChanceException(Object sender, FirstChanceExceptionEventArgs e)
at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource)
at System.Reflection.Assembly.ReflectionOnlyLoad(Byte[] rawAssembly)
at WixSharp.Utils.OriginalAssemblyFile(String file)
at WixSharp.Compiler.PackageManagedAsm(String asm, String nativeDll, String[] refAssemblies, String outDir, String configFilePath, Nullable`1 platform, Boolean embeddedUI, String batchFile)
at WixSharp.Compiler.ProcessCustomActions(Project wProject, XElement product)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Project.BuildWxs(OutputType type, String path)
at (Object , OutputType , String )
at SIDY.EXR.X(Object , OutputType , String )
at Invantive.Deploy.ProjectBase.Build()
at Invantive.Producer.Control.Setup.Program.Main() in C:\Users\gle3.WS212\Documents\ws-20.0\Invantive.Control\src\Invantive.Producer.Control.Setup\Program.cs:line 35
Striking is that the assembly is '', instead of a name. Also peculiar is the NotSupportedException occuring from OriginalAssemblyFile enumerating FirstOrDefault().
After downgrading to 1.14.2 for all of WIX#, it built again.
The problem might be caused by commit SHA-1: e816b3c02ec714a6e05e21e8cb871a23b3621d86
- Added prevention of assembly locking when building
ManagedProjectfrom cs-script host
which changed:
if (asm == null)
asm = Reflection.Assembly.ReflectionOnlyLoadFrom(file);
to
if (asm == null)
asm = Reflection.Assembly.ReflectionOnlyLoad(System.IO.File.ReadAllBytes(file));
The weird error message assembly name being '' may be a .NET Framework standard error, introduced since now the byte[] is used without specifying a source instead of the actual file name.
Suggestion is to add any way some checks on validation of byte[] and file in OriginalAssemblyFile method. And wrapping the ReflectionOnlyLoad in a try/catch which wraps the exception in it's own exception stating the file name, such as:
try
{
...
}
catch (Exception ex)
{
throw new Exception($"Can not reflection only load '{file}'.", innerException: ex);
}
For now I will resort to 1.14.2 again.
Thank you. Will look at it.
Yes loading assembly form memory stream creates file-disassociated assembly, which may in some case cause some problems.
I need to debug it. Can you please provide a use case to trigger the problem?
Managed Setup sample seems fine.
Hi @oleg-shilo ,
thanks. It is quite hard to construct a small reproduction scenario; we have a rather complex setup, but if deemed necessary I can create one.
However, might the WXS involved help?
Regards,
Guido
It may help if you just give me some extra details. It is a build error so debugging needs to happen. WXS usually helps with the runtime errors.
Is the error triggered by the specifying an invalid file path?
The trace stack indicates that it is GetLocation who raises the exception. But... the method is exception-protected:
```C#
public static string GetLocation(this System.Reflection.Assembly assembly)
{
if (assembly == null)
return null;
var location = "";
try
{
location = assembly.Location;
}
catch { }
string scriptAsmLocation = Environment.GetEnvironmentVariable("location:" + assembly.GetHashCode());
if (location.IsEmpty() && scriptAsmLocation.IsNotEmpty())
location = scriptAsmLocation;
return location;
}
```
Hi @oleg-shilo , I've just ran into this myself after upgrading from 1.14.2. Is there any known workaround for this bug at the moment?
I am yet to investigate this problem.
I have no test case to reproduce it.
May be you can help me with that?
Hi. I am not sure if it's the same cause, but I also encountered the same issue when upgrading to WixSharp 1.14.4.1 / WixSharp.Bin 1.14.4.
System.IO.FileLoadException: API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, Boolean fSkipIntegrityCheck, SecurityContextSource securityContextSource)
at System.Reflection.Assembly.ReflectionOnlyLoad(Byte[] rawAssembly)
at WixSharp.Utils.OriginalAssemblyFile(String file)
at WixSharp.Compiler.PackageManagedAsm(String asm, String nativeDll, String[] refAssemblies, String outDir, String configFilePath, Nullable`1 platform, Boolean embeddedUI, String batchFile)
at WixSharp.Compiler.ProcessCustomActions(Project wProject, XElement product)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Compiler.BuildWxs(Project project, OutputType type)
at WixSharp.Compiler.Build(Project project, String path, OutputType type)
at WixSharp.Compiler.Build(Project project, OutputType type)
In my case it is most likely something to do with the fact that I am using
project.DefaultRefAssemblies.Add(@"packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll");
to include the library used in the custom actions.
I am able to reproduce the issue with the provided files.
cs files.zip
I hope it helps
Excellent. Thank you so much.
I can reproduce it.
It took only a month and a half but I have the test case now. 馃槃
Will work on it asap.
Found the problem.
To my disbelieve I found that ReflectionOnlyLoad has a defect. It can only be executed once!
Second call ReflectionOnlyLoad will always throw the exception.
```C#
var file = @"..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll";
var asm = System.Reflection.Assembly.ReflectionOnlyLoad(System.IO.File.ReadAllBytes(file));
// the next line will throw the exception
asm = System.Reflection.Assembly.ReflectionOnlyLoad(System.IO.File.ReadAllBytes(file));
```
I am not sure when they introduced this new "feature" but it seems to me that the method did work in prev .NET versions. Of course I can be wrong but I definitely never had problems of this sort before. And the the documentation is silent about this:
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.reflectiononlyload?view=netcore-3.1
Will release the work around soon
Please update WixShar.Bin to version 1.14.4.2-HotFix
Install-Package WixSharp.bin -Version 1.14.4.2-HotFix
Please let me know if it addressed the issue you are having and I will publish this release as a proper one (not pre-release).
I can confirm that I can build properly with the hotfix. Thanks for the quick response :)
Yes, same here :)
Thank you guys. Will do the proper release asap.
Done. The new release is available now
Release v1.14.6.0
https://github.com/oleg-shilo/wixsharp/releases/tag/v1.14.6.0
It may help if you just give me some extra details. It is a build error so debugging needs to happen. WXS usually helps with the runtime errors.
Thanks for fixing it. I forgot to provide you with data. My apologies.
All good. We got there eventually :)