bilaldursun1 / nettopologysuite

Automatically exported from code.google.com/p/nettopologysuite
0 stars 0 forks source link

The invoked member is not supported in a dynamic assembly. #114

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create WKTReader instance under .net 4.0
2. GeometryServiceProvider.cs calls ReflectInstance, because no 
geometryprovider is defined.
3. ReflectInstance throws exception

What is the expected output? What do you see instead?
A new WKTReader instance is expected, an Exception shows up instead.

What version of the product are you using? On what operating system?
NTS 1.12.4448.22555, GeoAPI 1.6.4448.22541

Please provide any additional information below.
It seems this has to do with the running NTS under .net 4.0. See: 
http://bloggingabout.net/blogs/vagif/archive/2010/07/02/net-4-0-and-notsupported
exception-complaining-about-dynamic-assemblies.aspx for a solution

Original issue reported on code.google.com by prinsjer...@gmail.com on 8 May 2012 at 11:40

GoogleCodeExporter commented 9 years ago
only a question? you're manually changed target framework to 4.0, right?
so actually this isn't a no problem related to a "released" version.

Original comment by diegogu...@gmail.com on 9 May 2012 at 6:30

GoogleCodeExporter commented 9 years ago
NTS Released version 1.12 used in a framework 4.0 project will raise this 
exception.

Original comment by prinsjer...@gmail.com on 9 May 2012 at 6:39

GoogleCodeExporter commented 9 years ago
ok now it's clear

Original comment by diegogu...@gmail.com on 9 May 2012 at 6:47

GoogleCodeExporter commented 9 years ago
can you confirm that this code (that uses the trunk version of NTS+GeoAPI) 
works also for you?

Original comment by diegogu...@gmail.com on 9 May 2012 at 10:01

Attachments:

GoogleCodeExporter commented 9 years ago
Yes that works for me. When I add the following method, you see that there are 
no dynamic assemblies loaded in the console application. The application which 
causes the problems however, does have a dynamic assembly.

        private static void ReflectInstance()
        {
            var a = AppDomain.CurrentDomain.GetAssemblies();
            foreach (var assembly in a)
            {
                if (assembly.IsDynamic)
                {
                    Console.WriteLine("dynamic");
                }
            }
        }

Original comment by prinsjer...@gmail.com on 9 May 2012 at 10:24

GoogleCodeExporter commented 9 years ago
Have you referenced proj.net dll? I suspect that the problem come from this dll.

Original comment by diegogu...@gmail.com on 9 May 2012 at 10:28

GoogleCodeExporter commented 9 years ago
I use proj.net yes, but I suspect Castle Windsor is causing it. I cannot change 
the ReflectInstance method in GeometryServiceProvider.cs because nhibernate 
spatial uses NTS 1.12. 

Original comment by prinsjer...@gmail.com on 9 May 2012 at 10:35

GoogleCodeExporter commented 9 years ago
I'm experiencing a similar problem and the cause looks proj.net, but I need to 
investigate furthermore

Original comment by diegogu...@gmail.com on 9 May 2012 at 10:42

GoogleCodeExporter commented 9 years ago
I think if you skip all dynamic assemblies in ReflectInstance of 
GeometryServiceProvider, the problem will be solved. In my opinion NTS should 
work if a dynamic assembly is in memory.

Original comment by prinsjer...@gmail.com on 9 May 2012 at 11:01

GoogleCodeExporter commented 9 years ago
assembly.IsDynamic is from 4.0, so I'm trying to skip if one of these are true:

assembly is System.Reflection.Emit.AssemblyBuilder
assembly.GetType().FullName != "System.Reflection.Emit.InternalAssemblyBuilder"
assembly.GlobalAssemblyCache && assembly.CodeBase == 
Assembly.GetExecutingAssembly().CodeBase

taken from the post you've segnaled

Original comment by diegogu...@gmail.com on 9 May 2012 at 11:08

GoogleCodeExporter commented 9 years ago
This is a patch for GeoAPI hat maybe should fix the problem.
I'm not sure of this because I've not able to reproduce the problem, also in my 
code that sometimes all works and sometimes shows the error.

Original comment by diegogu...@gmail.com on 9 May 2012 at 11:26

Attachments:

GoogleCodeExporter commented 9 years ago
How can I use this patch with version 1.12?

Original comment by prinsjer...@gmail.com on 9 May 2012 at 12:32

GoogleCodeExporter commented 9 years ago
you should rebuild NTS from code, and then rebuild NHibernate.Spatial using the 
new NTS reference.
Not the easier task to do, sorry.
Actually, I'm not sure the patch fix anything.

Original comment by diegogu...@gmail.com on 9 May 2012 at 12:41

GoogleCodeExporter commented 9 years ago
How do I get the source for NTS 1.12? When I get the source for revision 818 or 
820 (is this the correct revision for 1.12?), I get lots of build errors. The 
source is not available in the downloads section. 

Original comment by prinsjer...@gmail.com on 15 May 2012 at 1:09

GoogleCodeExporter commented 9 years ago
checkout directly the trunk: 
http://code.google.com/p/nettopologysuite/source/checkout
if you see lots of build errors, maybe nuget is unable to download the 
dependencies

Original comment by diegogu...@gmail.com on 15 May 2012 at 1:15

GoogleCodeExporter commented 9 years ago
Well I have a lot of other projects that depend on NTS 1.12 and the GeoAPI 
version that matches it.

Original comment by prinsjer...@gmail.com on 15 May 2012 at 1:26

GoogleCodeExporter commented 9 years ago
so you can take the tag:
http://code.google.com/p/nettopologysuite/source/browse/tags/v1.12

Original comment by diegogu...@gmail.com on 15 May 2012 at 1:40

GoogleCodeExporter commented 9 years ago
The patch works perfectly! I added the patch to version 1.12 and everything 
works as it should in .net 4.0, with dynamic assemblies and in MVC4.

Thanks a lot for your support (and for pointing out I needed to learn to work 
with branches/tags in SVN ;)

Original comment by prinsjer...@gmail.com on 16 May 2012 at 7:12

GoogleCodeExporter commented 9 years ago
I've experienced in my code the patch I suggest and for me sometimes doesn't 
worked.
Actually, I'm unable to have a reproducible error, so it's hard for me to say 
that the patch is resolutive. Anyway, happy to see that this works for you :)

Original comment by diegogu...@gmail.com on 16 May 2012 at 7:19

GoogleCodeExporter commented 9 years ago
applied patch to GeoAPI repository with changeset: 67147
see http://geoapi.codeplex.com/SourceControl/changeset/changes/67147

Original comment by diegogu...@gmail.com on 16 May 2012 at 7:56

GoogleCodeExporter commented 9 years ago
Actually I've experienced sometimes that the problem appears again, in a 
randomic way :(
Here an explaination that can be helpful: http://goo.gl/jZOiu
"If a type can't be loaded for some reason during a call to Module.GetTypes(), 
ReflectionTypeLoadException will be thrown. Assembly.GetTypes() also throws 
this because it calls Module.GetTypes()"

Original comment by diegogu...@gmail.com on 23 Jul 2012 at 3:23

GoogleCodeExporter commented 9 years ago
here a patch that I think should be evaluated before the commit.

Original comment by diegogu...@gmail.com on 23 Jul 2012 at 3:43

Attachments:

GoogleCodeExporter commented 9 years ago
The patch does not work for me. Adding             
catch (TypeLoadException)
{
   return new List<Type>();
}
after catching the reflectiontypeloadexception in GetLoadableTypes fixed my 
problem. The problem was an exception which was thrown because an assembly was 
not loaded yet.

System.TypeLoadException
Could not load type 'Xft.Core.Model.Ilias.IliasAansluiting' from assembly 
'Xft.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

System.TypeLoadException: Could not load type 
'Xft.Core.Model.Ilias.IliasAansluiting' from assembly 'Xft.Core, 
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
   at System.Reflection.RuntimeAssembly.GetExportedTypes()
   at GeoAPI.GeometryServiceProvider.GetLoadableTypes(Assembly assembly) in G:\Jeroen\Projects\NTS1.12_JPR_Fixnet4\GeoAPI\GeoAPI\GeometryServiceProvider.cs:line 20

Cheers,

Jeroen. 

Original comment by prinsjer...@gmail.com on 25 Jul 2012 at 10:21

GoogleCodeExporter commented 9 years ago
maybe both alternatives can be handful, thanks

Original comment by diegogu...@gmail.com on 25 Jul 2012 at 10:29

GoogleCodeExporter commented 9 years ago
modified patch committed with changeset 68128

Original comment by diegogu...@gmail.com on 25 Jul 2012 at 10:34

GoogleCodeExporter commented 9 years ago
@prinsjeroen:
Where did you get NHibernate.Spatial relying on NTS v1.12?

Original comment by felix.ob...@netcologne.de on 2 Aug 2012 at 11:38

GoogleCodeExporter commented 9 years ago
@felix, I don't know. I spent too much time searching for compatible versions 
of NH,NH-spatial, NTS, GeoApi and Sharpmap. I made some modifications to get it 
all to work together properly.

Original comment by prinsjer...@gmail.com on 15 Aug 2012 at 6:21

GoogleCodeExporter commented 9 years ago
Can the GeoAPI NuGET be rereleased with this patch?

Original comment by byte...@bytenik.com on 25 Sep 2012 at 3:02

GoogleCodeExporter commented 9 years ago
please see GeoAPI 1.6.1

Original comment by felix.ob...@netcologne.de on 1 Oct 2012 at 12:50