Hi,

I have recently been trying to use Cecil to instrument a set of
assemblies that are designed to be used within the .NET Compact
Framework environment. I am having difficulty doing this, and have
boiled down my problem to the following code sample not working as I
expected:

      string executable = @"C:\some\path\to\an\assembly.dll";
      AssemblyDefinition assembly =
AssemblyFactory.GetAssembly(executable);
      AssemblyFactory.SaveAssembly(assembly, executable);

>From my understanding this code snippet should load an assembly into
cecil's object model and then save it back to disk essentially
unchanged at the semantic level.

If I run this on my main *.exe assembly the .NET Compact Framework CLR
appears to be happy to load my application. However if I run this code
snippet on any assemblies (*.dll) referenced by my main executable my
application will fail to load.

What I am seeing is a wait cursor appear for a very long time,
eventually followed by a TypeLoadException being reported. Enabling
the NETCF loader log file, has only made me more puzzled, as can be
seen by the following output:

Loading module [\Program Files\TestApplication\TestApplication.exe]
Trust verification passed. Module [\Program Files\TestApplication
\TestApplication.exe], Trust [2], Proc [2].
Policy file not present. [\Program Files\TestApplication
\TestApplication.exe.config]
Loading module [\Program Files\TestApplication\TestLibrary.dll]
Trust verification passed. Module [\Program Files\TestApplication
\TestLibrary.dll], Trust [1], Proc [2].
Missing Type. Class [TestLibrary.Class1], Assembly [TestLibrary,
Version=1.0.2845.16516, Culture=neutral, PublicKeyToken=null].
Loading module [\Program Files\TestApplication\TestLibrary.dll]
Loading module [\Program Files\TestApplication\TestLibrary.dll]
Loading module [\Program Files\TestApplication\TestLibrary.dll]
...

I am not sure why there are multiple Loading module ..... messages at
the bottom of the log file(that seems to be the symptom of the issue).
Those keep going on until eventually you get a TypeLoadException and
the application aborts. Usually there should only be one "Loading
module XYZ" line, followed either by a success or failure report.

Using a tool such as reflector the replaced assembly looks "normal"
and it defiantly includes a class called Class1 within the namespace
TestLibrary, and peverify appears to indicate no errors with the cecil
genereated assembly.

By contrast using cecil to instrument assemblies on the desktop
version of the framework is working really well.

Does anyone have any ideas on what may be going on here and/or things
which I could possibly investigate to diagnose it further?

Thanks,
Christopher Fairbairn


--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to