开发者

How to Check .Net 2.0 assembly for Calls to .Net 3.5

开发者 https://www.devze.com 2022-12-29 05:12 出处:网络
I\'ve found an issue I believe where an assembly is making a call to a .Net3.5 method in a .Net2.0 only environment. (None on the .Net service packs nor .Net 3.5 is installed)

I've found an issue I believe where an assembly is making a call to a .Net3.5 method in a .Net2.0 only environment. (None on the .Net service packs nor .Net 3.5 is installed)

I开发者_如何学Python'd like to know if there are any programs that I can run like FXCop to check an assembly for adherence to only making method calls that are available in .Net 2.0 without the 3.5 extensions that were added.

I've been bitten by this before and I'd like to have a way to check assemblies so that before they are released they can be checked to prevent these kinds of issues.

Please don't say require .Net 3.5 because whilst I'd like to go to this, it's just not possible at this point.


There's no such thing as a ".NET 3.5 method", there are only .NET 3.5 assemblies. Added to the .NET 2.0 release, just like .NET 3.0. The base 2.0 classes and the CLR haven't changed, using a method from a type that is only available in .NET 3.5 is easily avoided by using the Target Framework version feature in Visual Studio.

Well, that's the company line. It isn't quite accurate, they actually did change the 2.0 assemblies in a few selected spots. Without changing the [AssemblyVersion], very naughty. The best example is WaitHandle.Wait(int). It didn't exist in the original 2.0 release, it got added in 3.5

They papered this over by concurrently releasing .NET 2.0 SP1 with .NET 3.5, it does have the added method. Again with .NET 3.5 SP1, concurrent with .NET 2.0 SP2. Fwiw, these service packs don't just add missing methods, they also fix known stability and security problems.

There is no tool that I'm aware of that can check if your code fails when .NET 2.0 RTM. The client was supposed to deploy the service packs. They are hard to avoid, Windows Update pushes them. If you want to support a client that refuses to deploy the updates then you'll have to test your code on a virgin .NET 2.0 install.


In Visual Studio, you can specify the target framework in your application's properties. Go to the Application tab and change "Target Framework" from ".NET Framework 3.5" to ".NET Framework 2.0". Recompile and the compiler will issue errors if you try to reference anything outside of the 2.0 stuff.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号