Not working with .NET 4.0

Topics: Help
Dec 27, 2010 at 2:20 PM

Even though I added the suggested <startup>-section to my app.config, the map won't work.

When I'm trying to display a map, blue tiles with the text "The type initialized for 'SingletonCreator' threw an exception." appear :(

Hope someone has an idea what the problem could be.

Coordinator
Jan 3, 2011 at 12:37 PM

invalid xml, targeting not x86 cpu?

Jan 13, 2011 at 11:56 AM

dear alopx and radioman:

I solve the problem by   choosing  map source  "serveronly"

but I Met a new problem: I can't import or export the data.

when I try to solve the problem by delete "# if sqlite   #endif ","SingletonCreator.instance " throw  a exception.

Coordinator
Jan 13, 2011 at 12:01 PM
Edited Jan 13, 2011 at 12:01 PM

sqlite database is not working, use x86 target and set config file, also you can switch to mssqlce by removing SQLite string from compilation symbols

p.s. i mean it doesn't work for You ;}

Jan 13, 2011 at 2:20 PM

thanks for your reply .

Yes.It does not work when I choose  target  platform.net4.

When I choose  target  platform.net3.5,everything goes well.

Coordinator
Jan 13, 2011 at 2:30 PM

did you added configuration for .net4?

Jan 13, 2011 at 11:55 PM
Edited Jan 13, 2011 at 11:56 PM

Yes  .I have added configuration for .net4. And I have Examined Demo.WindowsForms.

The Demo.WindowsForms has the same problem.

It has a  default file app.config (1) and It's default  Target Framwork is .net 2

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

It runs well.

 

 

But when I right click on the project and select properties item. then set the Target Framwork as .net 4 ,Here  throws a Exception.
 

namespace GMap.NET
{
   using System;

   /// <summary>
   /// generic for singletons
   /// </summary>
   /// <typeparam name="T"></typeparam>
   public class Singleton<T> where T : new()
   {
      // ctor
      protected Singleton()
      {
         if(Instance != null)
         {
            throw (new Exception("You have tried to create a new singleton class where you should have instanced it. Replace your \"new class()\" with \"class.Instance\""));
         }
      }

      public static T Instance
      {
         get
         {
            return SingletonCreator.instance;
         }
      }

      class SingletonCreator
      {
         static SingletonCreator()
         {

         }
         internal static readonly T instance = new T();
      }
   }
}

O(∩_∩)O哈哈~

Coordinator
Jan 14, 2011 at 6:39 AM

well the last time i tested .net4 there was no problems, i'll try again

Coordinator
Jan 14, 2011 at 6:42 AM

as expected everything works just fine, you better start reading documentation ;]

Jan 14, 2011 at 11:11 AM
Edited Jan 14, 2011 at 11:11 AM

Found my problem some minutes after my post.

Problem was, that the SQLite.dll could not be found so I changed to ServerOnly.

 

I use .NET 4 and didn't have any problems except the missing dll ;)

Coordinator
Jan 14, 2011 at 11:17 AM

so you didn't solve anything ;] but there is it => useLegacyV2RuntimeActivationPolicy="true"

Jan 17, 2011 at 1:03 AM
Edited Jan 17, 2011 at 2:55 AM

Sorry, My English is not good enough to explain the problem . 

I means that  the project goes well when  select  .net4 platform.

Then select the "ServerOnly" option , everything goes well,and I can see the map .

But When I want to Export(Import) the data by click on "Export button", it throws an Exception . 

Is there the same problem with you?

Best regard for you.

 

ps: I'm not sure what "useLegacyV2RuntimeActivationPolicy="true" means. 

 

Coordinator
Jan 17, 2011 at 6:55 AM
  1. check http://greatmaps.codeplex.com/documentation
  2. copy EXACT config file content
  3. it works perfectly
Jan 18, 2011 at 2:47 AM
Edited Jan 18, 2011 at 2:51 AM

Thank you very much !

The problem is solved.

  1. copy EXACT config file content
  2. delete "# if sqlite   #endif "  

Thanks again.

Coordinator
Jan 18, 2011 at 7:03 AM

..what do you mean "delete # if sqlite #endif " ??

Jan 18, 2011 at 8:26 AM
Edited Jan 18, 2011 at 8:28 AM

in my project ,Sqlite is unavailble ,so I delete it.

public bool ShowExportDialog()
      {
#if Sqlite



 
         if(Cache.Instance.ImageCache is GMap.NET.CacheProviders.SQLitePureImageCache)
         {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            {
               dlg.CheckPathExists = true;
               dlg.CheckFileExists = false;
               dlg.AddExtension = true;
               dlg.DefaultExt = "gmdb";
               dlg.ValidateNames = true;
               dlg.Title = "GMap.NET: Export map to db, if file exsist only new data will be added";
               dlg.FileName = "DataExp";
               dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
               dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb";
               dlg.FilterIndex = 1;
               dlg.RestoreDirectory = true;

               if(dlg.ShowDialog() == true)
               {
                  bool ok = GMaps.Instance.ExportToGMDB(dlg.FileName);
                  if(ok)
                  {
                     MessageBox.Show("Complete!", "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Information);
                  }
                  else
                  {
                     MessageBox.Show("  Failed!", "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Warning);
                  }

                  return ok;
               }
            }
         }
         else
         {
            MessageBox.Show("Failed! Only SQLite support ;/", "GMap.NET", MessageBoxButton.OK, MessageBoxImage.Warning);
         }







#endif
         return false;
      }

 

 

Coordinator
Jan 18, 2011 at 8:31 AM

why it's unavailble?

Jan 18, 2011 at 8:31 AM
Edited Jan 18, 2011 at 8:32 AM
hl3292 wrote:

Yes  .I have added configuration for .net4. And I have Examined Demo.WindowsForms.

The Demo.WindowsForms has the same problem.

It has a  default file app.config (1) and It's default  Target Framwork is .net 2

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

It runs well.

 

 

But when I right click on the project and select properties item. then set the Target Framwork as .net 4 ,Here  throws a Exception.

namespace GMap.NET
{
   using System;

   /// <summary>
   /// generic for singletons
   /// </summary>
   /// <typeparam name="T"></typeparam>
   public class Singleton<T> where T : new()
   {
      // ctor
      protected Singleton()
      {
         if(Instance != null)
         {
            throw (new Exception("You have tried to create a new singleton class where you should have instanced it. Replace your \"new class()\" with \"class.Instance\""));
         }
      }

      public static T Instance
      {
         get
         {
            return SingletonCreator.instance;
         }
      }

      class SingletonCreator
      {
         static SingletonCreator()
         {

         }
         internal static readonly T instance = new T();
      }
   }
}

O(∩_∩)O哈哈~

YES,I lost the  useLegacyV2RuntimeActivationPolicy="true".

If some body see it ,

please use this 

<?xml version="1.0"?>
<configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
   </startup>
</configuration>


Jan 20, 2011 at 6:02 AM

It's  a mistery to me,too.

I'm trying to find out the reason.

Jan 21, 2011 at 7:49 PM

A mystery here too.

1) I have a running demo application running w/.NET 4.0, WPF, build to x86 platform, on Windows 7 64-bit, VS2010, that I wrote by moving pieces over from the GMap demo

2) My larger application in which I'm attempting to add a little mapping functionality is :

  • .NET4.0 / WPF
  • Build to x86 platform
  • Has been using Sqlite for persistence
  • Has had the correct <startup useLegacyV2.... , Sqlite has been working fine for months
  • I copy/bring my code from my demo application into my larger application

...I get the System.TypeInitializationException: The type initailizer for 'SingletonCreator'... at SqLitePureImageCache.AtlerDBAddTimeColumn

So, I recompiled GMap against my version of Sqlite and compiled it to .NET4.0.

If I come up with a solution I'll post it ASAP.

--- Ted

Coordinator
Jan 21, 2011 at 8:08 PM

hm, did your solution contains other projects with target set to AnyCPU?

Jan 21, 2011 at 9:36 PM

All projects are targeted correctly.  I did find and correct the issue.

First, I had been migrating from 1.0.60.0 of SQLite to 1.0.66.0 .. different projects were referencing different versions.  Bad.  Changed all to SQLite 1.0.66.0

Second, there are two versions of SQLite 1.0.66.0, one with and one without the embedded unmanaged SQLite3 dll.  Both versions (same filename) were on my system.  I was using a mix of them... yikes. (FYI: the wrapper-only one is ~ 184K and the wrapper with the embedded unmanaged SQLite 3 dll ~ 850K.

App works given what I had done in my previous post.  All is good.

Thanks  --- Ted

Mar 3, 2011 at 12:09 PM

I seem to have the same similar conditions as you Ted but unfortunately I'm still struggling to make this work. I've downloaded GMap.Net, excluded the "hot build" project and recompiled GMap.Net with demo apps and everything looks great. I'm able to use both cache and cache+server modes in the demo-apps and the tiles are managed correctly and displayed in the map. However when I try to use the cache mode from within my own application I get the "Exception: The type initializer for 'SingletonCreator' threw an exception." error in every tile displayed. My environment:

64-bit XP
WPF
All projects are targeted as x86
All projects are targeted as .Net FW4
I've added the "<startup useLegacy..." stuff to the App.config file
A reference to v1.0.66.0 of the System.Data.SQLite assembly with a size of 883Kb (I'm a complete newbie to SQLite but I reckon that this should be the .Net-wrapper AND db-engine)

Uncached a.k.a. "ServerOnly" works great in my app but as soon as I use cache mode I get the exception mentioned above. What am I doing wrong here...?

Cheers!
/Peter

Coordinator
Mar 3, 2011 at 1:20 PM

can you zip your test project?, i'll try it on my machine

Mar 4, 2011 at 8:19 AM
Edited Mar 4, 2011 at 11:13 AM

Sorry Radioman but I'm not allowed to disclose my project for various reasons:-( However, I decided to investigate this further and here are my findings:

I decided to leave my app altogether, for the time being, and focused on the behavior of one of the GreatMap demo-apps (Demo.WindowsPresentation - the WPF-app) and here are my findings.

NOTE: For GMap.NET.WindowsPresentation I use FW3.5 and target x86 for all of the scenarios below and the environment is 64-bit XP.

Setup 1 - WORKS IN *ALL* MODES ("ServerOnly", "ServerAndCache", "CacheOnly")!
GMap.NET.Core: Framework 2.0, target x86
Conditional Compilation Symbols: MONOdisabled; MySQLdisabled; SQLite
Demo.WindowsPresentiation: Framework 3.5, target x86

Setup 2 - WORKS IN *ALL* MODES ("ServerOnly", "ServerAndCache", "CacheOnly")!
GMap.NET.Core: Framework 2.0, target x86
Conditional Compilation Symbols: MONOdisabled; MySQLdisabled (this effectively activates my SQLCE 3.5 instance as "SQLite" has been removed)
Demo.WindowsPresentiation: Framework 3.5, target x86

Setup 3 - WORKS IN "ServerOnly" MODE ONLY!
GMap.NET.Core: Framework 2.0, target x86
Conditional Compilation Symbols: MONOdisabled; MySQLdisabled; SQLite
Demo.WindowsPresentiation: Framework 4.0, target x86

Setup 4 - WORKS IN *ALL* MODES ("ServerOnly", "ServerAndCache", "CacheOnly")!
GMap.NET.Core: Framework 2.0, target x86
Conditional Compilation Symbols: MONOdisabled; MySQLdisabled (this effectively activates my SQLCE 3.5 instance as "SQLite" has been removed)
Demo.WindowsPresentiation: Framework 4.0, target x86

I hope this will help you nail down the issue... :-)

Cheers,
/Peter

Coordinator
Mar 4, 2011 at 1:33 PM

once again, use this application config file when targeting .net4, works perfectly with sqlite:

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

Mar 4, 2011 at 1:53 PM

...which I already have. This is what my App.config looks like:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

Again this is for my "main app". As I mentioned we're running PRISM so there are a number of projects in my solution *but* the application has the above in the App.config file.

/Peter

Coordinator
Mar 4, 2011 at 2:21 PM
Edited Mar 4, 2011 at 2:26 PM

do you target .net4 or .net4-client-profile?

p.s. it works on both, but i use win7-x64

Mar 4, 2011 at 2:53 PM

FYI Litsegard,

On Windows 7 32bit, I have to target .NET 4.0

When I target 4.0 Client Profile, I get this: "Exception: The type initializer for 'SingletonCreator' threw an exception."

Coordinator
Mar 4, 2011 at 3:06 PM

client profile use this configuration:

<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
</configuration>

Mar 7, 2011 at 6:10 AM
Edited Mar 7, 2011 at 6:11 AM

First I'd like to thank you for trying to help me out here but unfortunately I'm not able to get this working. I've tried both .Net4 and .Net4-client profile and switched between the App.configs mentioned above but I still get the same "singleton exception" when compiling the core for SQLite. I'll discuss with my project group how to proceed with this - switch to SQLServer Compact which works great from what I've seen so far (the downside of this would leave us with an app relying on two db-engines: SQLite & SQLServer Compact), or another path. :-(

Cheers
/Peter

Coordinator
Mar 7, 2011 at 8:09 AM

hm, i'll make test project configured to .net4 and x86, maybe you missed something...

Mar 7, 2011 at 10:57 AM

Hmmmm, I think I've found the culprit! Among my projects I had a reference to the Core and WindowsPresentation dll later in the build chain which effectively replaced the correct builds. Sigh:-( Of course, now when I've made sure that we're using the correct build everything seems to look fine:-) I'm sorry for the inconvenience and frustration this may have caused you.

Cheers,
/Peter

Coordinator
Mar 7, 2011 at 1:50 PM

sounds the problem solved ;}