Loading CLR 2.0 dlls in to CLR 4.0 process, any downsides? - .net-4.0

Are there any downsides, like perf, or debugging capability reduction if I'm shoving in a dll linked with the 2.0 CLR?
I'd love to move all our sources to .NET 4.0, but some of our partners are using our base code in 2.0, which is forcing us to either keep multiple binaries of our stuff, or stay within 2.0 realms.
Any ideas on how to use MSBuild to make multiple copies of the same project in 2.0 and 4.0 would be awesome as well.

No, perf and debuggability is not going to be affected.
The only downside is that the assembly will run with .NET framework assemblies that it has never been tested with. The odds that this causes problems is very small but not nil. The .NET 4 assemblies have a handful of obscure bug fixes that alter behavior. And add a few bugs itself. These cases are way too obscure to list or take seriously.

Related

Is possible to create a MS Office com add-in using .Net 5 and an unmanaged shim?

Since VSTO has yet not been ported to .NET Core, can I do it the old fashioned way and create a unmanaged shim to load the CLR and host the managed .Core 5 add-in?
My particular use case is an Outlook COM add-in that is currently built using VSTO against .NET framework 4.7 but I want to start leveraging .NET 5. In terms of interaction with Outlook, it just adds some buttons on the Ribbon and makes a few calls into the Outlook object model. I don't need to do anything like VSTO document based add-in in Excel for example.
I don't want to down the JS path as there is quite a bit of C# code that would need to be ported.
I found this https://github.com/jozefizso/COMShimWizard/releases which shows how to do it with the .NET framework, and am assuming its pretty close if not identical to what the shim wizard did back in VS 2010.
Since I need to load .NET 5 I believe to load the CLR I will need to do something along the lines of what is outlined here: https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting.
Before I dig further into it, is the approach likely to work? In particular, will in be possible to do necessary COM gymnastics to instantiate the managed components?
And assuming all this is feasible, will this be more or less equivalent to what VSTO does for .NET framework 4.x, i.e. is it less safe or performant in any way or will there be any functionality that won't be available compared with an add-in built with VSTO?
Update 1
I did some more research which raised some additional potential issues.
For the .NET framework case, once a class has been loaded into the CLR it is relatively easy to "unwrap" the returned reference to get a COM pointer which can be used to access COM interfaces that the type implements. It is not clear to me how this can be done when loading the .NET Core runtime using netfxr interface.
.NET Core does not have the concept of app domains, does that mean the multiple add-ins loaded into the Core runtime would not be isolated, or there a way to achieve some degree of isolation? From what I have read it seems that maybe their heaps would at least be isolated but I'm not sure.
Update 2
From reading this https://github.com/dotnet/runtime/blob/main/docs/design/features/COM-activation.md it seems that in Core, requests to types in assemblies as COM servers will result in auto loading the Core runtime (if it isn't already loaded) and create the object in a separate AssemblyLoadContext so maybe a shim is not needed at all? On the other hand it seems that if the Core runtime is already loaded and the version does match what is required by type you are trying to create, then the type will fail to load, so that seem to be a problem...

Missing .net 4.5 property in PortableLibrary code

I'm writing a Windows Phone framework with Windows 8 in mind. That means I'm creating a Portable Class Library (PCL) to be used in both platforms.
Right now my PCL is targeting .NET 4.5, Windows Phone 8 and Windows Store apps, as you can see in the project properties.
In that project I need to use Path.DirectorySeparatorChar but I get the following error from the compiler:
System.IO.Path' does not contain a definition for 'DirectorySeparatorChar'
I understand that that particular char might be different in the different targeted OS (I really don't know if they are) but why is the compiler complaining about it? I mean, the property help doc says it is supported by .net framework 4.5, am I targeting the right framework? Is the PCL really targeting the full .net framework 4.5?
With respect to Path.DirectorySeparatorChar:
As far as I remember we've removed it from Windows Store in order to discourage manual parsing of paths. In general you should use Path.Combine() for assembling paths and Path.GetDirectoryName() for splitting them up. In order to check for invalid chars, there is another method that allows retrieving those.
So practically speaking, what do you need the property for?
Update: To answer your original question around understanding profiles: The profiles represent API intersections between the platforms you've selected in the PCL dialog. Generally speaking, the fewer platforms you target and the more recent the versions, the more APIs you get. Checking all platforms in the oldest version basically gives you the lowest common denominator.
Since you've targeted .NET 4.5 and .NET Windows Store, you can't access Path.DirectorySeparatorChar because that property isn't included in Windows Store.
So, here's the actual answer to this question taken from the MSDN forum.
When you are creating a PCL, you can only have a subset of API-s that are defined in that particular profile. A profile is a list of API-s visible in all platforms.
Now, even if some API exists in both individiual platforms, this doesn't mean that it will automatically be in the PCL profile. Why is it missing is anyone's guess, but you cannot infer those reasons yourself.
If you take a look at the official documentation on MSDN (Cross-Platform Development with the .NET Framework), you'll notice that there are several constraints on what can be shared. I guess that that particular property doesn't satisfy those constraints.
And a good way of knowing is a particular method is supported relies on the icons of the documentation
Your PCL can use .NET methods which are available to all of its targets. Since PathDirectorySeparator isn't available to Windows Store apps it isn't available in PCLs targeting Windows Store apps. You can see that it doesn't have the green shopping bag marker for store support at http://msdn.microsoft.com/en-us/library/system.io.path.aspx

Is it 'acceptable' to release .NET 4 based software yet (Nov 2009)?

I'm writing a small free tool. It's currently in Beta testing using .NET 3.5 but there's at least one aspect from .NET 4 I'd like to incorporate.
So, is it jumping the gun a bit to release .NET 4 based software?
Thx!
Wait till atleast the public release of .NET 4.0 before releasing anything other than early beta software with it.
I'm excited about alot of the new stuff too, but beta software built on a framework that is itself in beta is a recipe for disaster if you ask me.
Writing code for 4.0 might make sense. Releasing for general consumption prior to its official release seems foolish to me. Minor changes in 4.0 between now and the official release could cause your code to break. It would likely be easy to fix, but until you do your users are mad at you for putting out (what appears to them to be) a buggy program.
I read somewhere that VS2010 comes with a go-live license, meaning you can. Not sure I would, though. (See other answers...)
Well, you'd be forcing people to download and install Beta software. People may be reluctant or even unable to do this so, if nothing else, you're limiting your audience.
Also anything built with the Beta software isn't guaranteed to be compatible with the final released version.
I wouldn't go for the full framework, but including libraries like the CTP for the Task Parallel Library if your application is heavily multithreaded would be OK since you can just ship the .dll with you application and your users won't have to download anything. However, even with the TPL I would watch out, it's quirky and can slow your algorithms by an order of magnitude on things that should seemingly run just fine. The CTP is already over a year old though.

Have Microsoft rewritten Windows Workflow Foundation in .NET 4.0?

I heard from a friend that Microsoft rewrote all the Windows Workflow Foundation (WF) again and changed everything was in .Net 3.5.
Is that true?
And what about what we learned about WF in 3.0 and 3.5?
According to this article:
http://visualstudiomagazine.com/articles/2009/01/01/windows-workflow-changes-direction.aspx
Windows Workflow Foundation 4.0 is a "bottom-up rewrite with entirely new thinking...WF 3.0/3.5 will remain part of the framework and will run side by side with WF 4.0. This lets you manage the transition at a time that fits your organization's broader goals."
...which is code for, "We know we just screwed up your programming model, but we have a long term strategy, so we hope you will forgive us."
The article goes on to say that
The gains are enormous: custom
activities take center stage, and
authoring them is much simpler;
workflows are entirely declarative;
and there are three workflow flow
styles that you can combine
seamlessly. It's possible that you
could see a 10-fold improvement in the
time required to create and debug
workflows, in addition to 10- to
100-fold runtime performance
improvements.
The change is not without its detractors. In this article at DotNetKicks, the author states that "Microsoft is seriously damaging the Dot Net developer community and adoption in the industry with these half baked product releases and abrupt about-faces after shipping."
Which is why I generally wait for the 2.0 or 3.0 version of Microsoft technologies, although I made an exception for ASP.NET MVC.
We found the workflow product to be difficult to wrap your head around when it came time to pass data in and out. Scott Allen had a series of articles that did a good job describing the process, but still this was not at an easy task.
That's what the word on the street is. And on the internet. 3.0 and 3.5 will be deprecated, but still available.
Is this change not in Visual Studio 2010 beta 1? Download it, find out, and tell Microsoft what you think of it.

Backporting a VB.Net 2008 app to target .Net 1.1

I have a small diagnostic VB.Net application ( 2 forms, 20 subs & functions) written using VB.Net 2008 that targets Framework 2.0 and higher, but now I realize I need to support Framework 1.1. I'm looking for the most efficient way to accomplish this given these constraints:
I don't know which parts of the application are 2.0-specific.
I could reconstruct the forms without too much trouble.
I need to support SharpZipLib
My current idea is to find and install VB.Net 2003, copy over my code and iteratively re-create the tool. Are there better options?
Your app sounds small enough that I would create a fresh project/solution in a separate folder for the 1.1 framework, copy over the necessary files, use the "Add Existing Item" option, and then build. All the problems will bubble up to the surface that way.
A rather "ugly" approach, but it'll show you everything you need to fix up front.
Probably not. If you don't understand which bits are 2.0-specific, you're probably going to have to go the trial-and-error route. However, you can probably save yourself quite a bit of work if you go looking for generics beforehand. In my experience, those are the most numerous 1.1-incompatible bits that tend to make it into my code.
If you can gets your hands on VS 2010, you can (finally) target multiple frameworks. So within one project, you should be able to compile your 2.0 project to 1.1 and see what breaks.