Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono.Cecil.AssemblyResolutionException #243

Open
akusmin opened this issue Feb 2, 2023 · 0 comments
Open

Mono.Cecil.AssemblyResolutionException #243

akusmin opened this issue Feb 2, 2023 · 0 comments

Comments

@akusmin
Copy link

akusmin commented Feb 2, 2023

I could not find subj issue description anywhere. Placing my investigation here. I hope you will be able to find permanent solution.

All dependencies should be in the execution or bin folder ('.' or 'bin') according to Mono.Cecil assembly resolution logic.

                protected BaseAssemblyResolver()
                {
	                directories = new Collection<string>(2) { ".", "bin" };
                }
		public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
		{
			Mixin.CheckName(name);
			Mixin.CheckParameters(parameters);
			AssemblyDefinition assemblyDefinition = SearchDirectory(name, directories, parameters);
			if (assemblyDefinition != null)
			{
				return assemblyDefinition;
			}
			if (name.IsRetargetable)
			{
				name = new AssemblyNameReference(name.Name, Mixin.ZeroVersion)
				{
					PublicKeyToken = Empty<byte>.Array
				};
			}
			assemblyDefinition = SearchTrustedPlatformAssemblies(name, parameters);
			if (assemblyDefinition != null)
			{
				return assemblyDefinition;
			}
			if (this.ResolveFailure != null)
			{
				assemblyDefinition = this.ResolveFailure(this, name);
				if (assemblyDefinition != null)
				{
					return assemblyDefinition;
				}
			}
			throw new AssemblyResolutionException(name);
		}
		protected virtual AssemblyDefinition SearchDirectory(AssemblyNameReference name, global::System.Collections.Generic.IEnumerable<string> directories, ReaderParameters parameters)
		{
			string[] array = ((!name.IsWindowsRuntime) ? new string[2] { ".exe", ".dll" } : new string[2] { ".winmd", ".dll" });
			global::System.Collections.Generic.IEnumerator<string> enumerator = directories.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					string current = enumerator.get_Current();
					string[] array2 = array;
					foreach (string text in array2)
					{
						string text2 = Path.Combine(current, name.Name + text);
						if (File.Exists(text2))
						{
							try
							{
								return GetAssembly(text2, parameters);
							}
							catch (BadImageFormatException)
							{
							}
						}
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			return null;
		}

There is workaround: build self-contained assembly (flag '-r').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant