Nuget packages for .net 4.0 seem to require 4.5

570 views
Skip to first unread message

Miles Waller

unread,
Sep 20, 2013, 2:22:49 PM9/20/13
to castle-pro...@googlegroups.com
Hi,

I upgraded a .net 4.0 project that was working fine to the latest packages I could get from nuget:

  <package id="Castle.Core" version="3.2.0" targetFramework="net40" />
  <package id="Castle.Windsor" version="3.2.1" targetFramework="net40" />

The project builds and runs fine from the command line.  I have VS 2012 installed, so the 4.5 runtime exists on my machine too, however the project is 4.0 and I am using only 4.0 binaries.

I then went to run the executable on a machine that did not have the 4.5 runtime installed.  My program blows up with this exception:

An exception occurred creating the service: QuartzServer ---> System.MissingMethodException: Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.
   at Castle.MicroKernel.Registration.AssemblyFilter.<Castle.Core.Internal.IAssemblyProvider.GetAssemblies>d__5..ctor(Int32 <>1__state)
   at Castle.MicroKernel.Registration.AssemblyFilter.Castle.Core.Internal.IAssemblyProvider.GetAssemblies()
   at Castle.MicroKernel.Registration.Classes.FromAssemblyInDirectory(AssemblyFilter filter)

CurrentManagedThreadId is only available in the 4.5 runtime.

Installing the 4.5 runtime on the target machine fixed the problem.

Has something incompatible slipped into the releases?  I looked  on github but I couldn't find the root of this stack trace.

Thanks

Miles

Krzysztof Kozmic

unread,
Sep 20, 2013, 7:05:29 PM9/20/13
to castle-pro...@googlegroups.com, Rossi Jonathon
Hey Miles,

very interesting. It would appear you're correct. The call to Environment.CurrentManagedThreadId is part of the compiler-generated state machine (notice yield return in the method).

If you install Windsor 3.2 (instead of 3.2.1 that you're currently using) it works fine, so that may be a solution until we figure out what has gone wrong.

It looks like our .NET 4.0 build does actually compile like .NET 4.5


Jono - any idea what might be causing it? I'd suspect that it may have something to do with our migration to a new build server and some configuration difference between the two… Not that I really know what actually is the cause of that.

-- 
Krzysztof Kozmic

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.

Miles Waller

unread,
Sep 23, 2013, 5:58:23 AM9/23/13
to castle-pro...@googlegroups.com, Rossi Jonathon
Thanks Krzysztof,

I'll downgrade for the moment.

Cheers,

To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-users+unsub...@googlegroups.com.

Jonathon Rossi

unread,
Sep 24, 2013, 3:08:37 AM9/24/13
to Castle Project Users
Sorry for the delayed reply, I've been on leave.

That is strange. Looking at the build logs for the last master build of the 4.0 and 4.5 build configurations it is picking the right mscorlib when calling csc, so I'd have expected the 4.0 one to fail compilation, unless that bit isn't actually "compiled".
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll

IIRC our old build machine didn't have .NET 4.5 on it, and since 4.5 patches 4.0 that might have something to do with it.

OK, I've found this article which describes the problem, but I don't know how to fix it yet because the reference assemblies are there and being used. I thought the .NET team would have learnt their lesson with 3.5SP1 around patching previous versions.

I'll see if I can take another look later today.
--
Jono

Krzysztof Koźmic

unread,
Sep 26, 2013, 12:33:50 AM9/26/13
to Castle Project Users

Any luck with that?

Jonathon Rossi

unread,
Sep 26, 2013, 9:46:46 AM9/26/13
to Castle Project Users
Unfortunately I didn't have much luck getting much more time to look deeper into it on Tuesday. However, I've got it starred to look into it on the weekend.

Jonathon Rossi

unread,
Sep 28, 2013, 4:27:53 AM9/28/13
to Castle Project Users
Krzysztof I took your word for it the other day that the .NET 4.0 binaries were compiled wrong, but after decompiling them with dotPeek I can't reproduce what you saw. Both the binaries in castle.windsor.3.2.1.nupkg and both the binaries in a local compile are as I expected.

Miles and Krzysztof could you please check the binaries you have got. Maybe NuGet it giving you the wrong binary when you install it into a 4.0 project.

\lib\net40:
      [DebuggerHidden]
      public GetAssemblies>d__5(int <>1__state)
      {
        base..ctor();
        this.<>1__state = param0;
        this.<>l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
      }

\lib\net45:
      [DebuggerHidden]
      public GetAssemblies>d__5(int <>1__state)
      {
        base..ctor();
        this.<>1__state = param0;
        this.<>l__initialThreadId = Environment.CurrentManagedThreadId;
      }
--
Jono

Krzysztof Kozmic

unread,
Oct 5, 2013, 6:29:26 PM10/5/13
to castle-pro...@googlegroups.com
Obviously, Jono is right.

While I verified that compiling in .net 4 mode emits different code than .net 4.5 mode (thus ruling out any mistake on our part) WIndsor 3.2.1 for .net 4 does indeed do the right thing, therefore rendering my suspicion that something in our build configuration might be off invalid.

Miles, while your packages.config points to net40 version of the packages, perhaps your .csproj points to .net 4.5 version?
Please check the output of your application, whether the version of Castle you're getting there is the one for .net 4.0 or .NET 4.5

-- 
Krzysztof Kozmic

image.png

Ilya Petuhov

unread,
Nov 8, 2016, 6:25:54 AM11/8/16
to Castle Project Users
I've got the same kind of a problem, but with Casle.Core. Yet my solution doesn't compiles at all when calling (re)build solution, but still can be compiled one-by-one project.
Here's the VS build output:
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3275: The primary reference "C:\...\maxkpd.app.client.dll" could not be resolved because it has an indirect dependency on the assembly "Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

So I switched back to Castle.Core 3.2.2. Maybe you should check the Core also?

--
Ilya Petukhov

воскресенье, 6 октября 2013 г., 1:29:26 UTC+3 пользователь Krzysztof Koźmic написал:

Any luck with that?

To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-users+unsub...@googlegroups.com.

To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.




--
Jono

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-users+unsub...@googlegroups.com.

To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-users+unsub...@googlegroups.com.

To post to this group, send email to castle-pro...@googlegroups.com.
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jono



--
Jono

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-users+unsub...@googlegroups.com.

Jonathon Rossi

unread,
Nov 8, 2016, 7:09:40 AM11/8/16
to castle-pro...@googlegroups.com
Hi, your error message is completely different to the one reported in this 3 year old thread.

The compiler will usually give you that error when the referenced assembly is actually marked as being compiled with a newer framework via the TargetFrameworkAttribute.

I'd make sure you've got the assemblies you expect, I just checked Castle Core 3.3.3 on nuget.org and .NET 4.0 and 4.5 have the right assemblies:

> [assembly: TargetFramework(".NETFramework,Version=v4.0,Profile=Client", FrameworkDisplayName = ".NET Framework 4 Client Profile")]
> [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

Jono

To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.




--
Jono

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.



--
Jono



--
Jono

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.
To post to this group, send email to castle-pro...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to castle-project-u...@googlegroups.com.

To post to this group, send email to castle-pro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages