Discussion:
[mono-cecil] How to fix "Failed to resolve assembly"
Yang Zhang
2016-06-01 03:44:28 UTC
Permalink
Hi,

I am working on edit existing string/icon resource in assembly. I use
mono.cecil to parse, edit the resource and save. Almost all the localized
resource files work fine, but only the English original resource file does
not work. The English project contains core logic code and references other
dlls (OtherDLL.dll), this may cause exceptions when using mono.cecil, the
test code and exception is below.

AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(resourceFileName);// Some code
assemblyDefinition.Write(newFileName); // This will cause exception: "Failed to resolve assembly: 'OtherDLL, Version=10.1.1.1, Culture=neutral, PublicKeyToken=null'


The English dll is TestDll.dll under deployment directory, and other
localized resource dlls are TestDll.resources.dll under localized
directory, like /de/TestDll.resources.dll and /zh-CN/TestDll.resources.dll.
(other localized resource files could be well parse and save, but English
resource file failed.)

So how could I fix the issues? If it is the limitation or bug, could we use
another walk around method to achieve the goal?

Thanks in advance,
Yang
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jb Evain
2016-06-06 17:52:34 UTC
Permalink
The exception tells you that in order to write your assembly, Cecil needs
to read OtherDLL.

This happens when there's a metadata element that requires to read the
definition of a type in another assembly.

The solution is to pass an assembly resolver when reading the assembly that
knows how to resolve OtherDLL.

It could look like this:

var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory("C:\path\to\directory\which\contains\other\");

var assembly = AssemblyDefinitiob.ReadAssembly(fileName, new
ReaderParameters { AssemblyResolver = resolver });

Jb
Post by Yang Zhang
Hi,
I am working on edit existing string/icon resource in assembly. I use
mono.cecil to parse, edit the resource and save. Almost all the localized
resource files work fine, but only the English original resource file does
not work. The English project contains core logic code and references
other dlls (OtherDLL.dll), this may cause exceptions when using mono.cecil,
the test code and exception is below.
AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(resourceFileName);// Some code
assemblyDefinition.Write(newFileName); // This will cause exception: "Failed to resolve assembly: 'OtherDLL, Version=10.1.1.1, Culture=neutral, PublicKeyToken=null'
The English dll is TestDll.dll under deployment directory, and other
localized resource dlls are TestDll.resources.dll under localized
directory, like /de/TestDll.resources.dll and /zh-CN/TestDll.resources.dll.
(other localized resource files could be well parse and save, but English
resource file failed.)
So how could I fix the issues? If it is the limitation or bug, could we
use another walk around method to achieve the goal?
Thanks in advance,
Yang
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yang Zhang
2016-06-08 05:27:34 UTC
Permalink
Thanks. It is really a perfect solution for me, and now it could fix my
issue.

Regards,
Yang
Post by Jb Evain
The exception tells you that in order to write your assembly, Cecil needs
to read OtherDLL.
This happens when there's a metadata element that requires to read the
definition of a type in another assembly.
The solution is to pass an assembly resolver when reading the assembly
that knows how to resolve OtherDLL.
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory("C:\path\to\directory\which\contains\other\");
var assembly = AssemblyDefinitiob.ReadAssembly(fileName, new
ReaderParameters { AssemblyResolver = resolver });
Jb
Post by Yang Zhang
Hi,
I am working on edit existing string/icon resource in assembly. I use
mono.cecil to parse, edit the resource and save. Almost all the
localized resource files work fine, but only the English original resource
file does not work. The English project contains core logic code and
references other dlls (OtherDLL.dll), this may cause exceptions when using
mono.cecil, the test code and exception is below.
AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(resourceFileName);// Some code
assemblyDefinition.Write(newFileName); // This will cause exception: "Failed to resolve assembly: 'OtherDLL, Version=10.1.1.1, Culture=neutral, PublicKeyToken=null'
The English dll is TestDll.dll under deployment directory, and other
localized resource dlls are TestDll.resources.dll under localized
directory, like /de/TestDll.resources.dll and /zh-CN/TestDll.resources.dll.
(other localized resource files could be well parse and save, but English
resource file failed.)
So how could I fix the issues? If it is the limitation or bug, could we
use another walk around method to achieve the goal?
Thanks in advance,
Yang
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...