4
  • Created a new Class Library (Package) project
  • Changed the project.json to look like this (added project dependencies):

project.json

    { 
         "version": "1.0.0-*",
         "description": "WMI.ECM.PCMS.Services.Acomba Class Library",
         "authors": [ "WILL" ],
         "tags": [ "" ],
         "projectUrl": "",
         "licenseUrl": "",

         "dependencies": {
           "Acomba.SDK": "2.0.0",
           "WMI.ECM.Inventory.Models": "",
           "WMI.ECM.Inventory.Services": "",
           "WMI.ECM.Inventory.Services.Contracts": ""
      },

         "frameworks": {
             "dnx451": { },
             "dnxcore50": {
                "dependencies": {
                  "Microsoft.CSharp": "4.0.1-beta-23516",
                  "System.Collections": "4.0.11-beta-23516",
                  "System.Linq": "4.0.1-beta-23516",
                  "System.Runtime": "4.0.21-beta-23516",
                  "System.Threading": "4.0.11-beta-23516"
                }
             }
         }
     }
  • Compiled the solution, and I get this error:

The type 'DateTime' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PunlicKeyToken=b77a5c561934e089'.

  • Yet, I do not have this problem with my other projects which also target DNX451 and DNXCORE50. Also shall I mention that the mscorlib.dll is actually referenced in the project in question per this screenshot: Referenced assemblies.

As a result, I did some searches which end up clueless.

I tried to add dependencies to the dnx451{} in my project.json like so:

"dnx451": {
  "dependencies": {
    "Microsoft.CSharp": "",
    "System.Runtime": ""
    ...
  }
}

Because I remember having read such a solution somewhere, and it didn't work.

It looks like a common problem although I can't find any helpful solution to the actual problem.

Currently using

  • Visual Studio Community 2015 - Version 14.0.25123.00 Update 2
  • .NET Framework 4.6.01055
  • ASP.NET MVC 6 Installed
  • SideWaffle for Xunit DNX Unit Test Project Template
  • Visual C# 2015

UPDATE

It appears to be caused by the COM library which I imported using this tool from the VS CMD line: Tlbimp.exe (Type Library Importer).

In short, the AcoSDK.dll is a COM library which I imported using the above-mentioned tool to create a .NET assembly with all the COM types resolved as .NET types.

Then, I used NuGet.exe to create a package which I published over my private feed.

And then, I referenced the package in my project as "Acomba.SDK": "2.0.0" in my project.json.

Whenever I use a DateTime property from this package, the build error occurs. For example, this causes the error to occur:

public DateTime CreatedAt { get { return p.PrTimeModified; } }

And this doesn't:

public DateTime CreatedAt { get { return new DateTime(); } }

The COM type for a .NET DateTime is Date. However, it's supposed to be seen as a DateTime following the steps in the examples provided on the tlbimp.exe command line.

It is only when I added a dot to the property that I saw that the DateTime was not supported in DNXCORE50. Except that it is for native DateTime such as 'new DateTime()' (see screenshot here).

Any clue as to how to workaround this?

Community
  • 1
  • 1
Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162
  • Why on Earth are you doing this? Targeting CoreCLR/CoreFx is useful to get your code to run on Linux or OSX some day. That COM component never will. – Hans Passant May 11 '16 at 17:10
  • @HansPassant: Why not? I mean, once wrapped in a .NET imported type assembly, published as a NuGet package, and then referenced using the proper compatibility packages, what would prevent this COM to work on other OS? Plus, I am still on my learning curve here. =) – Will Marcouiller May 11 '16 at 17:39

1 Answers1

1

As per this issue reported on GitHub: Accessing mscorelib in DNX Core 5.0 #989, it seems that the Core CLR doesn't support well the COM types that refer to mscorlib.dll.

Besides, there's a package available to workaround this issue which is: Microsoft.NETCore.Portable.Compatibility.

In short, all it does is a remap of the types referencing to mscorlib.dll such as COM objects to the newer releases of System.Runtime and other libraries, which in turn refers to its corresponding DLL for the right version or so.

So the solution is to add this package in the project.json as follows:

project.json

"frameworks": {
  "dnx451": { },
  "dnxcore50": {
    "dependencies": {
      "Microsoft.CSharp": "4.0.1-beta-23516",
      "Microsoft.NETCore.Portable.Compatibility": "1.0.1-beta-23516",
      "System.Collections": "4.0.11-beta-23516",
      "System.Linq": "4.0.1-beta-23516",
      "System.Runtime": "4.0.21-beta-23516",
      "System.Threading" :  "4.0.11-beta-23516"
    }
  }
}

For greater details about this package, and to know more about the issue, I strongly suggest to follow the links provided as they cover a more in-depth information.

In the end, it solved the problem! =)

Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162