Silverfrost Forums

Welcome to our forums

Type Initialization Exception for .NET

8 Nov 2012 10:07 #10997

Hi!

I'am trying to recompile an existing program, written in fixed format, for the .NET platform. This program compiles and works fine for the Win32 platform, while it immediatly crashes if compiled for the NET, returning a Type Initialization Exception.

This is the minimum portion of the program generating the exception:

       program test
      
      implicit real(kind=2) (a-h,o-z)
      
      character(len=120):: path_mod,pmodl,name_mod,nmodl
      character(len=120):: name_hgt,nhght,name_cnv,nconv
      character(len=120):: path_pnt,ppnts,name_pnt,npnts
      character(len=120):: path_out,pout,name_out,nout

      parameter(path_mod = ' ',
     &          path_pnt = ' ',
     &          name_pnt = 'INPUT.DAT',
     &          path_out = ' ',
     &          name_out = 'OUTPUT.DAT')

      parameter(iumi     = 11,
     &          lmin     = 2,
     &          lmax     = 2190,
     &          name_mod = 'EGM2008_to2190_TideFree',
     &          aegm     = 6378136.3d0,
     &          gmegm    = 0.3986004415d20,
     &          isub     = 1,
     &          igrid    = 0,
     &          isw      = 82,
     &          exclud   = 9999.0d0)

      parameter(iuci     = 13,
     &          jmin     = 0,
     &          jmax     = 2160,
     &          name_cnv = 'Zeta-to-N_to2160_egm2008')
      
      stop
      end 

I cannot understand what's wrong. I'm working with FTN95 6 and Visual Studio 2008 on windows 7 x64.

9 Nov 2012 9:18 #11001

I have tried using your code from Plato and from the command line and there are no problems.

Try these two routes on your machine first so that we can identify if it is a problem with Visual Studio.

9 Nov 2012 11:48 #11008

Dear Paul, thank you for the reply. I can confirm that there are no problems with Plato, so the issue seems limited to the VS environment. Furthermore, I found that the exception raises only with CheckMate mode (on NET of course). Any ideas?

Thanks again for your help.

Emanuele

9 Nov 2012 1:05 #11010

The next thing to do is to look at the build log from Visual Studio. In the Output window, hold down the Ctrl key and click on the link for the build log.

In the build log, find the command line options for FTN95 and DBK_LINKx.

Now issue the same commands from a Command Prompt window (DOS box). If the same problem occurs then you can remove options selectively to see which one is causing the problem (besides /CHECKMATE which you know is OK).

9 Nov 2012 1:50 #11011

Thanks again. I did some tests and the problem seems to be in the combined use of /checkmate and /full_debug. In fact, by omitting one of the two, the program runs properly. And I read on the help that the /full_debug option implies something related to the parameter statements...

9 Nov 2012 6:40 #11012

I think that you can safely omit /full_debug. /full_debug implies /debug but you already have /debug in /check and /checkmate.

I am not sure what /full_debug does above /debug (as you say, something to do with parameters) but I will log this for investigation.

10 Nov 2012 1:53 #11016

Thanks for your help.

11 Nov 2012 5:10 #11020

Quoted from PaulLaidler I am not sure what /full_debug does above /debug (as you say, something to do with parameters) but I will log this for investigation.

/full_debug makes the values of parameters visible in the debugger.

12 Nov 2012 1:52 (Edited: 12 Nov 2012 4:17) #11021

Dear Paul,

I made other tests and I reproduced the exception also on [u:52fcdd9b86]Plato[/u:52fcdd9b86], wih the following code, which is the same as before but with some more declaration statements.

 program test 
      
      implicit real(kind=2) (a-h,o-z)
      
      character(len=120):: path_mod,pmodl,name_mod,nmodl 
      character(len=120):: name_hgt,nhght,name_cnv,nconv 
      character(len=120):: path_pnt,ppnts,name_pnt,npnts 
      character(len=120):: path_out,pout,name_out,nout 

      parameter(path_mod = ' ', 
     &          path_pnt = ' ', 
     &          name_pnt = 'INPUT.DAT', 
     &          path_out = ' ', 
     &          name_out = 'OUTPUT.DAT') 

      parameter(iumi     = 11, 
     &          lmin     = 2, 
     &          lmax     = 2190, 
     &          name_mod = 'EGM2008_to2190_TideFree', 
     &          aegm     = 6378136.3d0, 
     &          gmegm    = 0.3986004415d20, 
     &          isub     = 1, 
     &          igrid    = 0, 
     &          isw      = 82, 
     &          exclud   = 9999.0d0) 

      parameter(iuci     = 13, 
     &          jmin     = 0, 
     &          jmax     = 2160, 
     &          name_cnv = 'Zeta-to-N_to2160_egm2008')

      parameter(iusc     = 12,
     &          maxpt    = 1000000)

      parameter(maxr=100)
      
      parameter(ncols    = 1,
     &          nrows    = 1,
     &          nmax0    = max(lmax,jmax),
     &          nmax01   = nmax0+1,
     &          nmax02   = nmax0+2,
     &          jcol     = 1,
     &          jfft     = 1)

      parameter(zeta0    = -41.d0/100.d0)
      
      parameter(ae       =  6378137.d0,         
     &          gm       =  0.3986004418d20,  
     &          omega    =  7292115.d-11,
     &          c20      =  -0.484166774985d-03,
     &          rf       =  0.d0)

      real(kind=2) zonals(10),cz(20),da(5)
      real(kind=2) batch(ncols*maxr),grsv(15)
      real(kind=2) cnm(nmax01,nmax01),snm(nmax01,nmax01)
      real(kind=2) scrd(ncols,2),statd(22),ddlon(ncols)
      real(kind=2) flat(maxr),flon(maxr),dist(maxr),pt(maxr)
      real(kind=2) pt_a(maxpt),ga(maxpt),zeta(maxpt),corr(maxpt)
      real(kind=2) flat_a(maxpt),flon_a(maxpt),dist_a(maxpt),
     & horth_a(maxpt)

      real(kind=2) uc(maxr),tc(maxr),uic(maxr),uic2(maxr)
      real(kind=2) cotc(maxr),thet2(maxr),thet1(maxr),thetc(maxr)

      real(kind=2) pmm_a(nmax01,maxr+1),pmm_b(nmax01,maxr),f_n(maxr),
     & f_s(maxr)
      real(kind=2) p(nmax02,maxr),p1(nmax02,maxr),p2(nmax02,maxr)
      real(kind=2) c_ev(nmax01,maxr),s_ev(nmax01,maxr),kk(nmax01,maxr)
      real(kind=2) c_od(nmax01,maxr),s_od(nmax01,maxr)
      real(kind=2) cr1(jfft),sr1(jfft),cr2(jfft),sr2(jfft)
      real(kind=2) aux(2*jcol),wrkfft(2*jcol),factn(nmax01),k(nmax01)
      real(kind=2) cml(nmax01),sml(nmax01)

      real(kind=1) data(ncols,nrows)
      integer(kind=3) it(maxr),it_a(maxpt),iex(maxr),zero(maxr+1)
      
      stop 
      end 

Running with Checkmate NET option, I get the following error message in the prompt (sorry for the italian!):

12 Nov 2012 1:55 (Edited: 12 Nov 2012 4:17) #11022

System.TypeInitializationException: L'inizializzatore di tipo di 'Test' ha generato un'eccezione. ---> System.TypeInitializationException : L'inizializzatore di tipo di 'Salford.Fortran.RTLibrary' ha generato un'eccezione. ---> System.BadImageFormatException: Tentativo di caricare un programma con un formato non corretto. (Eccezione da HRESULT: 0x8007000B) in Salford.Fortran.RTLibrary.__com_plus_initialise(Int32 hin) in Salford.Fortran.RTLibrary.InitLibrary() --- Fine dell'analisi dello stack dell'eccezione interna --- in Salford.Fortran.RTLibrary.InitLibrary() in Test..cctor() --- Fine dell'analisi dello stack dell'eccezione interna --- in Test.TEST()

It is exactly the same exception I got in VS environment. Are you able to reproduce this behaviour? Thanks in advance!

12 Nov 2012 3:06 #11023

Quoted from Emanuele

I cannot understand what's wrong. I'm working with FTN95 6 and Visual Studio 2008 on windows 7 x64.

As you are running x64 version of Windows 7, are you sure that you are using 32 bit CLR?

I have set it as default on my computer, it goes something like:

C:\\WINDOWS\\Microsoft.NET\\Framework64\\v2.0.50727\\Ldr64.exe SetWow

To revert back to 64-bit CLR:

C:\\WINDOWS\\Microsoft.NET\\Framework64\\v2.0.50727\\Ldr64.exe Set64
12 Nov 2012 3:15 #11024

Your code compiles and links in Plato for me both with and without /full_debug.

12 Nov 2012 4:14 #11025

Thank everybody!

I tried by setting 'Ldr64.exe SetWow', as jalih suggested, and in fact the behaviour changes. I get no more initialization exception, but the program now crashes without any message! 😢 (only with /checkmate).

Regarding the CLR, I believed that the 32 bit version, was automatically chosen, considering that the /REF options of the compiler refer to the 32 bit versions of the NET dlls; but if it is not so, what are the consequences on redistribution?

12 Nov 2012 4:39 #11026

Quoted from Emanuele I get no more initialization exception, but the program now crashes without any message! 😢 (only with /checkmate).

Just tested this myself and got the same symptom...

However, there was infact a StackOverFlowException in the process. Try increasing the stack size on linker options, it worked for me!

12 Nov 2012 4:50 #11027

You are right, thanks!

Now the remaining question is what happens if I distribute an application to an end-user who has not set the CLR version to 32 bit by default?

14 Nov 2012 1:50 #11039

When you distribute your application, I'd recommend you don't compile with /checkmate. If you want an improved callback report when your application crashes, try only /Debug. If you are confident that your distributed application is working, then turn off all these checking options !!

14 Nov 2012 2:44 #11054

Thank you, John.

The problem is that (with the longer version of the code I posted) I get the application crashing also when compiled in Release (NET) configuration, if the option 'Set64' (which is the default) is set in Ldr64.exe.

I am going to test it also on other PCs...

Please login to reply.