Skip to content
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

"Make reference types nullable" must use nullable type in SetRelatedEntity() #501

Open
randombyte-developer opened this issue May 31, 2024 · 1 comment
Labels

Comments

@randombyte-developer
Copy link

Tool and Version
EarlyBoundGenerator V 2.2024.5.16

Describe the bug
I wanted to try out #311. It generates nullable types. When compiling the generated code there is a compile error:

Possible null reference argument for parameter 'entity' in 'void Entity.SetRelatedEntity<Contact>(string relationshipSchemaName, EntityRole? primaryEntityRole, Contact entity)'

The relevant line of code is
this.SetRelatedEntity<Contact>("account_primary_contact", null, value);

value can be null in this case. SetRelatedEntity() does handle null values correctly but the nullable entity type has to be used like this:
this.SetRelatedEntity<Contact?>("account_primary_contact", null, value);

To Reproduce
Steps to reproduce the behavior:

  1. Generate the code for an Account with nullable types enabled.
  2. Compile it.

Expected behavior
No errors.

Additional context
My C# project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
		<SignAssembly>true</SignAssembly>
		<AssemblyOriginatorKeyFile>........snk</AssemblyOriginatorKeyFile>
	</PropertyGroup>
	<PropertyGroup>
		<LangVersion>11.0</LangVersion>
		<TargetFramework>net462</TargetFramework>
		<Nullable>enable</Nullable>
		<Version>1.0.0.0</Version>
		<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
	</PropertyGroup>
	<ItemGroup>
	  <PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.52" />
	</ItemGroup>
</Project>
@randombyte-developer
Copy link
Author

A workaround is to not enable the INotifyPropertyChanging pattern in the EBG config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant