On deserializing using Newtonsoft, I get default constructor required issue on mac but not on window
I am trying to use the ChatGPT nuget package
<PackageReference Include="OpenAI" Version="1.11.0" />
which have to deserialize json for data processing. It works normally on windows, but on macos, I face the error below:
My target framework for windows is net8.0, and for macos, it is net8.0-macos. I have tried to switch to another ChatGPT package, but similar issue arises. Is there any fix for this issue? Thank you!14 Replies
I have also tried using some other Json libraries beside Newtonsoft, like Json.NET and Json.NET.Aot, but still same issue arises
Have you tried the built in System.Text.Json?
That said, there will need to be a constructor for the deserializer to use
Switching to a library that uses that causes a new error on mac:
In my .csproj, I have
<TrimMode>copyused</TrimMode>
set. net8.0-macos needs it for some reasonHm. Yeah try the source generated serialized and provide a manual context then
Don't know what else to suggest
I am confused around here.. I cannot really fix the library without cloning and adding it as a refernece.. will play around with other tags like LinkMode, PublishTrimmed, ...
"net8.0-macos needs it for some reason" according to who?
to be clear, the trimming is 100% what is breaking this
and there is no way for you to fix it. Newtonsoft does not work with trimming. these libraries need to be rewritten to work with trimming, you will keep running into random issues like this one
that said. it is definitely not a requirement to turn it on
Ah okay, thanks for the info
Looks like
partial
trim mode is kinda workingto be clear, you should set
<PublishTrimmed>false<PublishTrimmed>
instead of doing thiswhen I set that it shows the error that mac apps cannot be built with publish trimmed set to false on dotnet run
ok, i see. it does say to set
<LinkMode>None</<LinkMode>
in your project, though. does that not fix the problem?the program crashes on a run and when I see the error, it says it was not able to load interop, etc.. dll stuffs
trim mode partial seems to work. But it is causing some weird issue.
@reflectronic I was trying to root some of the libraries to avoid trimming but still it says to use the source generated serializer
the library causing the issue is the openai one
nvm,
I got it fixed
ye!
Just adding OpenAI instead of the Betalgo fixed it
how do I close this thread
with
/close