Skip to content

NullReferenceException with 3.0.0rc4 #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mike-welch opened this issue Jul 22, 2022 · 6 comments
Closed

NullReferenceException with 3.0.0rc4 #1884

mike-welch opened this issue Jul 22, 2022 · 6 comments

Comments

@mike-welch
Copy link

Environment

  • Pythonnet version: 3.0.0rc4
  • Python version: 3.9.13
  • Operating System: Windows 11
  • .NET Runtime: 4.8 (?)

Details

I am importing the DLL's for PLEXOS, a power system application compiled with .NET, to perform analysis on the simulation outputs, and I have built a wrapper around the .NET methods (see here for examples from the developers) to streamline the interaction. My use case is to use the API to extract data from a PLEXOS Solution File (a .zip with a bunch of binary files).

I've been trying to keep up with pythonnet updates and spend some time earlier in the year using alpha-2 which I was able to get working with minor updates. While I typically try to avoid alphas the latest PLEXOS versions are being compiled with .NET 6 and I wasn't having luck with 2.5.2; however, for compatibility they have also been providing the DLLs compiled with .NET 4.8 which is what I'm using here. (NOTE: I have since figured out that we're running into pythonnet/clr-loader#20 with the .NET 6 DLLs).

I've had a few spare cycles this week so I've been making updates to different tools including the wrapper mentioned above. One of these changes is updating from a2 to rc4, with the goal of bumping to the release when it is available. Unfortunately, I am running into some issues when trying to call the .NET methods and have been able to isolate that the code works with a2 and does not work with rc4.

With rc4 I am getting the following error:

Exception has occurred: NullReferenceException
Object reference not set to an instance of an object.
   at PLEXOS_NET.Core.Solution.QueryToCSV(String strCSVFile, Boolean bAppendToFile, SimulationPhaseEnum SimulationPhaseId, CollectionEnum CollectionId, String ParentName, String ChildName, PeriodEnum PeriodTypeId, SeriesTypeEnum SeriesTypeId, String PropertyList, Object DateFrom, Object DateTo, String TimesliceList, String SampleList, String ModelName, AggregationEnum AggregationType, String Category, String Separator)

I suspect the issue is with the enumerations. However, I know data of the right types is being passed to the function since if I change any of the input arguments (e.g. SimulationPhaseId as a string) I will get a TypeError and a message that "No method matches given argument."

Looking for some direction on what to debug next and appreciate any insights!

@filmor
Copy link
Member

filmor commented Jul 22, 2022

Thank you for testing out the Release Candidate.

You can attach a (.NET) debugger to the running Python process and see where exactly the exception is raised, without a stack trace or a reproducible example of some sort we won't be able to help you.

@mike-welch
Copy link
Author

I should have noted, everything I'm doing is from python and I'm working in VS Code. .NET is not my specialty, so I'll need some help on that debugging step. I took a look through some of the documentation on the wiki and it didn't look like it was relevant, requiring Visual Studio proper. Can you help point me in the right direction?

@filmor
Copy link
Member

filmor commented Aug 10, 2022

I have never tried to debug (apart from classic print debugging) outside of Visual Studio. The Community edition is free, so I suggest you try debugging with that.

@filmor
Copy link
Member

filmor commented Aug 11, 2022

I'd really like to fix this one before releasing the final 3.0, but there is really not much to go on here. Can you create a reproducible example for this case?

@mike-welch
Copy link
Author

I spent a little time working to get debugging set up with Visual Studio yesterday and didn't have much success getting the debugger attached. With little success, I approached the problem from a slightly different direction... I noted in the OP that I have a module set up to act as a wrapper around the .NET functionality to try and create a clear delineation between Python and .NET. Rather than use the wrapper, I opted to use the "regular" code:

import os
import sys
from pathlib import Path
import pandas as pd

# Add to PATH
dllPath = Path(r'C:\Program Files\Energy Exemplar\PLEXOS 9.0 API')
sys.path.append(str(dllPath))

import clr
clr.setPreload(True)

clr.AddReference('EEUTILITY')
import EEUTILITY.Enums  # type: ignore

clr.AddReference('PLEXOS_NET.Core')
import PLEXOS_NET.Core as PLEXOS  # type: ignore

clr.AddReference('EnergyExemplar.PLEXOS.Utility')
import EnergyExemplar.PLEXOS.Utility.Enums  # type: ignore

sol = PLEXOS.Solution()
sol.Connection("Model Test Solution.zip")

sol.QueryToCSV(
    'test.csv',
    False,
    EEUTILITY.Enums.SimulationPhaseEnum.STSchedule,
    EEUTILITY.Enums.CollectionEnum.SystemRegions,
    '',
    '',
    EnergyExemplar.PLEXOS.Utility.Enums.PeriodEnum.FiscalYear,
    EnergyExemplar.PLEXOS.Utility.Enums.SeriesTypeEnum.Statistics,
    '29',  # USE,
    None,
    None,
    '',
    '',
    '',
    EnergyExemplar.PLEXOS.Utility.Enums.AggregationEnum.All,
    '',
    ',',
)

sol.Close()

There are a couple other ways to pull data out of the file, those all seem to work both through the wrapper and with snippets similar to the above. While it seems like there is some change being introduced between 3.0.0a2 and 3.0.0rc4 I'm also not convinced it isn't due to something funky with the wrapper and class inheritance.

Given that other methods seem to work, and that the error seems to be isolated to code that I wrote, I am comfortable shelving this and taking a little more time to review things on my side.

@filmor
Copy link
Member

filmor commented Sep 17, 2022

I'll close this one for now, as there is nothing "actionable" from our side. I would suggest that you open a bug report on the vendor's Github and just reference me in it. Since their API is apparently .NET Core nowadays, they could really profit from having this work.

@filmor filmor closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants