What is the point of System.IO.dll? - .net-4.0

So far as I'm aware, most of the below types are now, and have always been, defined in mscorlib and/or System.dll.
However, in looking in the v4 framework directories (I have 4.5 installed, not sure if it also exists in Vanilla v4), I find an assembly called System.IO.dll.
Examining it in reflector, I can't see any actual code. All I can find are the following entries:
[assembly: TypeForwardedTo(typeof(BinaryReader))]
[assembly: TypeForwardedTo(typeof(BinaryWriter))]
[assembly: TypeForwardedTo(typeof(EndOfStreamException))]
[assembly: TypeForwardedTo(typeof(FileNotFoundException))]
[assembly: TypeForwardedTo(typeof(InvalidDataException))]
[assembly: TypeForwardedTo(typeof(IOException))]
[assembly: TypeForwardedTo(typeof(MemoryStream))]
[assembly: TypeForwardedTo(typeof(SeekOrigin))]
[assembly: TypeForwardedTo(typeof(Stream))]
[assembly: TypeForwardedTo(typeof(StreamReader))]
[assembly: TypeForwardedTo(typeof(StreamWriter))]
[assembly: TypeForwardedTo(typeof(StringReader))]
[assembly: TypeForwardedTo(typeof(StringWriter))]
[assembly: TypeForwardedTo(typeof(TextReader))]
[assembly: TypeForwardedTo(typeof(TextWriter))]
All pointing back to mscorlib (I think, haven't checked all of them). I've had a look around, and I can't see any framework version (e.g. silverlight, compact, etc) where these types aren't in mscorlib. So, does anyone know why this assembly exists (and why now)?

You found a reference assembly. That may sound odd, since you definitely don't use such a reference assembly in a .NET project that targets .NET >= 4.0. You normally get them from the C:\Program Files (x86)\Reference Assemblies directory on your dev machine. But that is not the only scenario in which a compiler is used. You also use a compiler when you use System.CodeDom in your program or depend on XML serialization.
Specific about System.CodeDom and XML serialization is that the compiler runs on your user's machine. And that you cannot target a specific .NET Framework version. Your user's machine does not have the targeting packs that your machine has. So its gets whichever version happens to be installed on the machine. The files in C:\Windows\Microsoft.NET\Framework\v4.0.30319 contains the reference assemblies that match that installed version. If the machine gets updated with another .NET 4.x release then those reference assemblies get updated as well.
Not the only possible scenario, likely that you'll also use them when you build from the command line. Or on a build server and decided to not pay for a VS license, very bad idea. Or in an ILMerge command, excessively bad idea. Those scenarios are a lot more troublesome. It works okay as long as the built assembly stays on the same machine. But not if they travel to another one machine, one that has a different framework version installed. That can produce pretty mystifying runtime exceptions, evident in this Q+A.
System.IO.dll is fairly exotic. You are only going to need it when you run System.CodeDom with a reference to a PCL assembly. Its primary role is to hide declarations, the kind that should not be used in the profile you picked. The System.IO namespace needs hiding because these types cannot be used when you target WinRT. But otherwise the reason that it doesn't contain any types, the [TypeForwardedTo] tells the compiler that the type is supported on a desktop machine and to look for the declaration elsewhere, mscorlib.dll

Related

C++/CLI project in C# solution usage

Maybe this header isn't decribe my problem exactly, but...
I have .NET Core console app project which uses C++/CLI project written as a wrapper for native C++ code from same dll.
So, both C# and C++/CLI project are compiled well, but when I run C# project, I get this error:
Could not load file or assembly 'Microsoft.VisualC.STLCLR, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
I checked this file on my disk - I have it installed in many directories on it. I wrote all paths I've found in the PATH enviroment variable, but no effect.
My configuration:
Windows Server 2016, .NET Core 3.1.102, MSVS 2019 16.4.3.
Please, can someone say me the reason of this error and give me a correct solution? Thnxs.
P.S. IF it needs I can add classes and data I use in my code.
P.P.S. I have it works under .NET Framework 4.8, but not .NET Core 3.1
I downloaded Microsoft.VisualC.STLCLR dll from
C:\Windows\Microsoft.NET\assembly\GAC_MSIL
and I put it on my repository and references it on my .net core project it works.
I am having the same error while migrating from .NET Framework 4.8 to .NET 6.
I tried to copy the dll side by side with my binaries but with no success.
Procmon did not even list any read of the DLL (I am an happy user of Procmon for many years).
To bypass the runtime error, I removed uses of the cliext namespace in our C++/CLI code.
In my case, I had to convert code depending on :
#include <cliext\set>
#include <cliext\functional>
#include <cliext\vector>
#include <cliext\algorithm>
The exception occured after a call to a method which was using one of the cliext container.
By chance, the amount of conversion work was minimal.

Unable to resolve assemblies that use Portable Class Libraries

I'm having a problem with assembly resolution on an end-user machine and I believe it's related to using Portable Class Libraries....
I have a .NET 4.0 application that was originally written in Visual Studio 2010. Recently we upgraded to Visual Studio 2012 and we've created a few projects that are Portable Class Libraries. I don't believe we need these features now, but we're also building a Windows 8 Store application that might benefit from these libraries.
When I compile my project, what exactly does the portable library feature do? I expect that it allows me to run it on different frameworks without modification or recompiling.
When I look at the library in reflector dotPeek it shows the Platform attribute as:
.NETPortable,Version=v4.0,Profile=Profile5
And the references seem 2.0-ish:
mscorlib, Version=2.0.5.0
System, Version=2.0.5.0
System.Runtime.Serialization, Version=2.0.5.0
When I run the application on this end-user's machine, I see an error in the log file:
Could not load file or assembly, 'System.Core, Version=2.0.5.0...'
Googling System.Core 2.0.5.0 seems to refer to SilverLight -- which appears to be one of the targeted frameworks.
This machine does not have Visual Studio installed, but has .NET 4.0 (4.0.3 update)
Is there something I should be doing differently to compile, something I should investigate in my dependencies or something I should be looking to install on the end-user machine? What does the 2.0.5.0 refer to?
For .NET 4, you need an update (KB2468871) for Portable Class Libraries to work. From the KB Article:
Feature 5
Changes to the support portable libraries. These changes include API
updates and binder modifications. This update enables the CLR to bind
successfully to portable libraries so that a single DLL can run on the
.NET Framework 4, on Silverlight, on Xbox, or on the Windows Phone.
This update adds public Silverlight APIs to the .NET Framework 4 in
the same location. The API signatures will remain consistent across
the platform. All modifications are 100 percent compatible and will
not break any existing code.
Also see the "Deploying A .NET Framework App" section of the MSDN Portable Class Library Documentation.
EDIT: Actually, if the machine has .NET 4.0.3 installed as you mention, that should be sufficient. Can you double-check to make sure that it is actually installed?

Serialized Assembly Won't Upload to Database

I have a CLR project that calls a simple HTTP web service. Its x64-targeted and I got it to serialize properly only after going through the steps outlined at the following link which talks about the changes required to have VS2010 point to the correct target architecture (x64) - the changes just required unloading and changing the .csproj file with a few extra lines to reference the correct version of sgen.exe: http://geekswithblogs.net/akraus1/archive/2011/12/10/148002.aspx
Now, I am able to build this project and its .XmlSerializers.dll by setting "Generate serialized assembly" to on. I wanna do this because my CLR project is going to get deployed on the database, and I don't want it to runtime serialize any objects since those DLLs are not referenced in my database and I don't want to give my CLR project permissions higher than EXTERNAL_ACCESS for security reasons because this will be used in a production environment where security is important, and also because my database is NOT trustworthy.
Long story short, I am following the guide at the following link to upload my serialized assembly into the database but I get an error: http://footheory.com/blogs/bennie/archive/2006/12/07/invoking-a-web-service-from-a-sqlclr-stored-procedure.aspx
The error is: CREATE ASSEMBLY for assembly '.XmlSerializers' failed because the assembly is built for an unsupported version of the Common Language Runtime.
Does anyone know how to correct this by forcing sgen.exe to serialize a CLR-supported version of the assembly? Viva the Stack.
SQL Server 2005/2008/2008R2 supports only .Net 2.0. You need to change your project to target this, see How to: Target a Specific .NET Framework Version or Profile. You do not need to specify x64 for the build target, SQLCLR assemblies should be Common target built.
That said, calling web services from SQLCLR is a really really really bad idea. Don't do it. Have an external process handle the HTTP calls.
I found that the problem was actually not the fact that I'm using .NET 3.5 as a target, but I was referencing the wrong version of the sgen.exe tool, which in this case I needed the x64 version of 6.0A (which translates to .NET 3.5) at this path: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sgen.exe. Now I am able to build the correct version of the serialization assembly, upload it, and also use it.

C++/CLI DLL namespace not found in MSVS

The big picture: what I am trying to accomplish is writing code in both C# and C++, to strike a good performance/productivity balance. It is not for code reuse reasons; I just want to be able to write new code in native C++ when it suits me, without committing to all its horrors.
I have a solution with 4 projects:
GUI: C# WPF interface
Logic_Cs: C# DLL, high level reference implementation of game logic
Logic_CLI: CLI DLL, interface between managed and unmanaged code
Logic_Cpp: C++ lib with native implementation
At some point, all of this was working just fine. In my GUI project I could switch between C#/C++ implementation merely by using the namespace from the appropriate DLL.
Then I apparently changed something, and now I can not get the namespace in the Logic_CLI project to be recognized in the GUI project, even though the Logic_Cs namespace still works just fine.
Yes, I added correct references, set dependencies, rebuilt AND recreated my entire solution structure from scratch; nothing helps.
I notice the C# DLL builds to a folder in its own project directory, while CLI builds to the solution directory; but the GUI application seems to look for the DLL's in their correct directory anyway, and im not getting any complaints about the DLL; it just refuses to import the namespace from it.
Earlier, when all this was working, I wasnt explicitly exporting anything from the CLI DLL; nor am I doing so for the C# DLL. It should 'just work', no?

Does referencing the JDK namespaces from within a .NET application require the Java runtime to be installed?

I'm in a VB.NET application. I have referenced some java.* namespaces in my file and am utilizing objects and methods from this namespace throughout the code. Presumably this is relying upon J# to compile.
Imports java.util
Imports java.util.zip
Imports java.io
Are these JDK namespaces fully contained in the .NET framework, or will my clients need to have Java installed when they go to run my application?
As a side note, I have not explicity referenced any external Java DLL's or anything. This is all pure .NET as far as my code is concerned.
Yes, they're within the J# DLLs, which I strongly suspect VB is referencing for you automatically. If you open your binaries up in Reflector, I'm sure you'll see a reference to vjslib.dll there.
There's no dependency on an actual JRE/JDK being installed.
Personally I would try to migrate away from them, however. If you need more compression options than System.IO.Compression it's worth looking at SharpZipLib. Microsoft no longer ships J# as a product, and the idea of trying to port all the Java 1.1.4 classes to .NET, including their quirks, has always made me nervous.
vjslib.dll doesn't even ship by default with either the framework or Visual Studio these days...