Closed Romanx closed 2 months ago
Hi - thanks for the bug report.
By specifying PrivateAssets="all" ExcludeAssets="runtime"
, you're saying that Vogen is a development-only dependency, which isn't strictly true. Vogen.dll
is, but Vogen.SharedTypes.dll
isn't.
The types specified in VogenSharedTypes
need to be there at runtime because the generated code references them. For your scenario, the path through the generated code hits EnsureInitialized
, which expects ValueObjectValidationException
to exist:
private readonly void EnsureInitialized()
{
if (!IsInitialized())
{
#if DEBUG
global::System.String message = "Use of uninitialized Value Object at: " + _stackTrace ?? "";
#else
global::System.String message = "Use of uninitialized Value Object.";
#endif
throw new global::Vogen.ValueObjectValidationException(message); // <=== THROWN HERE
}
}
... but that exception isn't present at runtime.
You could stop this from happening by specifying your own exception, e.g. in global config:
[assembly: VogenDefaults(throws: typeof(MyException))]
... but it is not recommended: doing so fixes your particular problem, but there are other shared types in Vogen.SharedTypes
, such as ValueObjectOrError
which is used if TryFrom
is generated.
Including it adds just 18KB and one DLL to the published app:
Looking at it in something like dotPeek, you can see the types that it exports:
I've updated the wiki with this information.
Thanks again for your feedback.
@SteveDunn thanks very much, we happily took the runtime dependency (which as you said is very small) when we found the error. Just got confused by the situation when it occurred. Thanks for updating the docs!
Very welcome!
Describe the bug
An exception is thrown when performing a comparision between two well constructed objects. This only seems to happen if you use
ExcludeAssets="runtime"
in your PackageReference.Steps to reproduce
Created a slimmed down repo project here: https://github.com/Romanx/VogenIssue
Expected behaviour
The runtime asset can be excluded and no exception is thrown when comparing the two objects.