clairernovotny / ReferenceGenerator

MIT License
75 stars 13 forks source link

Possible fix for null reference exception #27

Open ericsink opened 7 years ago

ericsink commented 7 years ago

I have a project.lock.json file that contains this:

 "targets": {
    ".NETStandard,Version=v1.0": {
        "Microsoft.NETCore.Jit/1.0.2": {},

And refgen.exe crashes on this because it expects that empty document to contain at least an item called "type".

In ProjectEngine.cs, around line 279, there is:

where string.Equals(packageObj.Property("type").Value.Value<string>(), "package", StringComparison.OrdinalIgnoreCase)

if I change this to

where packageObj.Property("type") != null && string.Equals(packageObj.Property("type").Value.Value<string>(), "package", StringComparison.OrdinalIgnoreCase)

refgen.exe stops throwing null reference exceptions.

I don't know if my code change is valid or if my project.lock.json is valid. I'm just sayin.

ericsink commented 7 years ago

More context:

This happened as I am upgrading SQLitePCL.raw to support netstandard. My project build system generates all the csproj files and project.json files, so it seems likely that I am doing something wrong which is causing Visual Studio to create a project.lock.json file that contains an element that is missing "type" : "package" where it is expected.

A possible clue is that I have several projects where a project.json file is involved, some uap10.0, some netstandard, and the only ones that are failing in this manner are the projects which depend upon another project in the solution. Not sure yet if this is relevant or not.

ericsink commented 7 years ago

More context:

This happens with 2.0.0-beta-bld14, but not with 1.4.2.

And originally I found the problem when calling refgen.exe from the command line, but it also happens when using the refgen nuget package.

clairernovotny commented 7 years ago

Hi @ericsink -- the best solution here, and really the reason why I haven't pushed this to stable, is that this tool is no longer needed. Instead, you should add a reference to netstandard.library 1.6.0 and leave it at that.

ericsink commented 7 years ago

Wow. So refgen isn't needed at all? What about uap10.0?

E

On Monday, August 8, 2016, Oren Novotny notifications@github.com wrote:

Hi @ericsink https://github.com/ericsink -- the best solution here, and really the reason why I haven't pushed this to stable, is that this tool is no longer needed. Instead, you should add a reference to netstandard.library 1.6.0 and leave it at that.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/onovotny/ReferenceGenerator/issues/27#issuecomment-238215058, or mute the thread https://github.com/notifications/unsubscribe-auth/ADsojbDZGJxcX4gpscKKEjsoknH3FYxKks5qdxnqgaJpZM4Jek5T .