Archived

This forum has been archived. Please start a new discussion on GitHub.

Could not load file or assembly Ice

Hi.

I'm developing an IceBox service in Visual Studio 2012. Resulting DLLs are transfered to Debian Squeeze virtual box. When I try to start the icebox service, I got this:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Ice, Version=3.5.1.0, Culture=neutral, PublicKeyToken=1f998c50fec78381' or one of its dependencies.
File name: 'Ice, Version=3.5.1.0, Culture=neutral, PublicKeyToken=1f998c50fec78381'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'Ice, Version=3.5.1.0, Culture=neutral, PublicKeyToken=1f998c50fec78381' or one of its dependencies.
File name: 'Ice, Version=3.5.1.0, Culture=neutral, PublicKeyToken=1f998c50fec78381'
-- 09/15/14 22:40:35.123 /opt/Ice-3.5.1/bin/icegridnode: Activator: detected termination of server `DeviceToken'
   exit code = 1

Please, advice.

Regards,
Dmitry

Comments

  • xdm
    xdm La Coruña, Spain
    If you build Ice with VS2012 and the default build configuration or you use Ice.dll from Windows binary distribution, The Ice.dll uses unmanaged code and this will not work with mono in Debian and could cause the load failure.

    If Ice.dll is build with mono or managed configuration you will not have such problems.

    You also need to ensure that Ice.dll can be loaded by installing it in GAC or setting the appropriate MONO_PATH environment variable.
  • xdm wrote: »
    If you build Ice with VS2012 and the default build configuration or you use Ice.dll from Windows binary distribution, The Ice.dll uses unmanaged code and this will not work with mono in Debian and could cause the load failure.

    If Ice.dll is build with mono or managed configuration you will not have such problems.

    You also need to ensure that Ice.dll can be loaded by installing it in GAC or setting the appropriate MONO_PATH environment variable.

    Thank you for prompt reply.

    1. I'm using Ice from binary distribution on Windows ( Visual Studio 2012; Windows 8.1 );
    2. I'm not transmitting Ice.dll with my icebox service to Debian machine;
    3. I have build Ice from source on Debian machine;
    4. I have gacutil'ed Ice.dll and the rest of the Assemblies on Debian machine;

    I am quite confused as to what I should try next. Please, see a few lines from the startup log file below:
    Mono: Assembly Loader probing location: '/usr/lib/mono/gac/Ice/3.5.1.0__cdd571ade22f2f16/Ice.dll'.
    Mono: Assembly Loader probing location: '/usr/lib/Ice.dll'.
    Mono: Assembly Loader probing location: '/usr/lib/mono/gac/Ice/3.5.1.0__cdd571ade22f2f16/Ice.exe'.
    Mono: Assembly Loader probing location: '/usr/lib/Ice.exe'.
    Mono: Assembly Loader probing location: '/usr/lib/mono/gac/Ice/3.5.1.0__cdd571ade22f2f16/Ice.dll'.
    Mono: Assembly Loader probing location: '/opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/Ice.dll'.
    Mono: Assembly Loader probing location: '/usr/lib/Ice.dll'.
    Mono: Assembly Loader probing location: '/usr/lib/mono/gac/Ice/3.5.1.0__cdd571ade22f2f16/Ice.exe'.
    Mono: Assembly Loader probing location: '/opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/Ice.exe'.
    Mono: Assembly Loader probing location: '/usr/lib/Ice.exe'.
    Mono: The following assembly referenced from /opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/bizzup.services.devicetoken.icebox.dll could not be loaded:
         Assembly:   Ice    (assemblyref_index=0)
         Version:    3.5.1.0
         Public Key: cdd571ade22f2f16
    The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/).
    
    Mono: Failed to load assembly bizzup.services.devicetoken.icebox[0x17288c0]
    
    Mono: Could not load file or assembly 'Ice, Version=3.5.1.0, Culture=neutral, PublicKeyToken=cdd571ade22f2f16' or one of its dependencies.
    

    PS please tell me what additional information should I provide for you to resolve this issue?

    Thank you for your time.
  • xdm
    xdm La Coruña, Spain
    I see, the problem here is the public key tokens, when you build Ice from sources in Debian Ice.dll PublicKey token is 1f998c50fec78381, but in Windows you are using a binary distribution so your service references Ice.dll with PublicKey token cdd571ade22f2f16.

    Maybe you can remap the public key tokens as explained here, Assemblies and the GAC | Mono

    Otherwise you will have to use a .NET source distribution in Windows so the referenced public key tokens matches your Debian assemblies.
  • Thank you for your help.

    Just for the records in hope others will benefit from it:
    1. I have put Ice.dll and IceBox.dll ( from Windows ) near my icebox service on Debian machine;
    2. According to startup log all the assemblies got loaded into icebox Domain;
    3. Now the log says the following:
    Missing method .ctor in assembly /opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/bizzup.services.devicetoken.icebox.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
    Mono: The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in bizzup.services.devicetoken.icebox
    Can't find custom attr constructor image: /opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/bizzup.services.devicetoken.icebox.dll mtoken: 0x0a000001
    
    xdm wrote: »
    I see, the problem here is the public key tokens, when you build Ice from sources in Debian Ice.dll PublicKey token is 1f998c50fec78381, but in Windows you are using a binary distribution so your service references Ice.dll with PublicKey token cdd571ade22f2f16.

    Maybe you can remap the public key tokens as explained here, Assemblies and the GAC | Mono

    Otherwise you will have to use a .NET source distribution in Windows so the referenced public key tokens matches your Debian assemblies.
  • xdm
    xdm La Coruña, Spain
    Hi,

    It seems that your service references System.Runtime.Versioning.TargetFrameworkAttribute that is new in .NET 4.0 and not available in Mono run-time you are using.

    Be aware that Ice.dll use some pre-processor directives so isn't the same the DLL build in Windows that the one build with Mono, even if it the loading doesn't fail you could encounter problems at run-time when it try to use some APIs that aren't available in Mono.

    I think the easier will be that you rebuild the service in your Debian machine.
  • xdm wrote: »
    I think the easier will be that you rebuild the service in your Debian machine.

    OK. I am going to change the whole build process of mine.

    Thank you for your time. :)
  • xdm
    xdm La Coruña, Spain
    If changing your build process it's a lot of work, you can rebuild Ice for .NET in Windows from sources and then copy the assemblies to the Ice-3.5.1\Assemblies directory, so when you rebuild the new assemblies are used and contains the correct pub key token.

    As for the "System.Runtime.Versioning.TargetFrameworkAttribute" you can remove that for your service or try to use mono --runtime argument to set 4.x runtime
    --runtime=v4.0.30319
    
  • I have tried the runtime switch with the following result:
    /usr/bin/mono --runtime=4.0.30319 /opt/Ice-3.5.1/bin/iceboxnet.exe
    
    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v2.0.50727
    

    PS not sure that iceboxnet.exe is the right candidate to test the runtime switch though.

    PPS regarding the build process — hacking is not what I really want, so if rebuilding from source is the right approach — I am definitely going to stick to it. No problem.

    Thank you for you time :)

    PPS I will report the progress here.
  • xdm
    xdm La Coruña, Spain
    /usr/bin/mono --runtime=4.0.30319 /opt/Ice-3.5.1/bin/iceboxnet.exe
    
    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v2.0.50727
    

    This indicates that your mono version doesn't support .NET 4 run-time, it was added with mono 2.8

    It's simpler to just build and run your service in the same platform
  • xdm wrote: »
    This indicates that your mono version doesn't support .NET 4 run-time, it was added with mono 2.8

    It's simpler to just build and run your service in the same platform

    There is obviously something wrong with my whole setup then. Please, look at the following output:
    mono --version
    Mono JIT compiler version 3.8.0 (tarball Thu Sep  4 12:22:04 UTC 2014)
    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
            TLS:           __thread
            SIGSEGV:       altstack
            Notifications: epoll
            Architecture:  amd64
            Disabled:      none
            Misc:          softdebug
            LLVM:          supported, not enabled.
            GC:            sgen
    
  • UPD

    well, actually I've managed to compile icebox service on windows 8 and run it on debian 7. a test service - a simple one just to be sure it can be started at all.

    the real icebox service's code requires .NET 4.0+ to run ( due to System.Threading.Tasks at least ).

    so, what is left unresolved: is it possible at all to run .NET 4.0+ under mono and Ice? had anyone succeeded to implement such a service and make mono use its v.4 profile ( much confused about these versions at the moment ).
  • OK. What has been done up to the moment:

    1. I have compiled mono from source (mono-3.8.0.tar.bz2).
    2. ...and installed it to /opt/mono
    3. ...and used update-alternatives for /usr/bin/mono to point to the /opt/mono/bin/mono executable
    4. ...rebuilt Ice for .NET ( the cs subdirectory ) ( Note: the make install script is broken, so you will need to manually copy all the files from the Assembly directory under the cs one to under your ICE_HOME ). Note that I have also disabled the MANAGED flag in the config file, for with this flag enabled the Ice for C# refused to build.
    5. ...restarted ice registry and nodes

    NB
    1. In my project under Windows I am using Ice.dll and IceBox.dll obtained from the target Debian machine ( I have manually put these two as references to the project )
    2. I switched from Visual Studio 2012 to Xamarin on Windows in order to avoid .NET specific tags. Not quite sure I should have to though.

    So, this time I am facing the following in the error log:
    Missing method System.Threading.Monitor::Enter(object,bool&) in assembly /opt/mono/lib/mono/2.0/mscorlib.dll, referenced in assembly /opt/io.bizz-up/zeroc/services.out/bizzup.services.devicetoken.icebox/bizzup.services.devicetoken.icebox.dll
    

    Note, though, that I use the System.Threading.Tasks namespace on Windows during debug. Not sure, but it seems that I will need to degrade my code to using plain Threads instead of tasks.
  • 2. I switched from Visual Studio 2012 to Xamarin on Windows in order to avoid .NET specific tags. Not quite sure I should have to though.

    Well, actually it seems to be quite safe to use Visual Studio 2012, provided that you stick to the 3.5 .NET runtime. So, I switched back to VS.
  • building mono from tarball

    just in case anyone cares, following is the command line used to build mono with support for all profiles:
    ./configure --prefix=/opt/mono  --with-profile2=yes --with-profile4=yes --with-profile4_5=yes --with-moonlight=no