-
Notifications
You must be signed in to change notification settings - Fork 495
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
The type 'PartitionKeyInternal' is defined in an assembly that is not referenced. #2264
Comments
Could you provide a repro CSPROJ? I created this CSPROJ:
Which contains just a single class that does this:
And it builds: I'm using NET 5.0.103: The same goes on VS 2019: |
Ok, this is a good one... It appears creating an instance of using Azure.Cosmos;
using System.Threading.Tasks;
namespace CosmosRepro
{
public class ReproClass
{
public async Task DoSomething()
{
var partitionKey = new PartitionKey("foo-bar-baz");
}
}
} I verified the using Azure.Cosmos;
using System.Threading.Tasks;
namespace CosmosRepro
{
public class ReproClass
{
public Task DoSomething()
{
var partitionKey = new PartitionKey("foo-bar-baz");
return Task.CompletedTask;
}
}
} Additionally, my .csproj is pretty bare: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Cosmos" Version="4.0.0-preview3" />
</ItemGroup>
</Project> Let me know if you need any more details. |
What is also weird, is that if you remove the
But it's particularly related to having an
Again, this only happens on .NET 5, not NET Core 3.1. I am no expert in the framework, but this really seems like an issue with |
Wondering if this should go to fx repo or Roslyn? |
This behavior is "By Design" in the compiler. The types in Azure.Cosmos.dll can’t be fully understood without looking at the Microsoft.Azure.Cosmos.Direct.dll reference which is not provided to the compiler. In particular in this case the compiler can't understand if The reason this is happening only when the method is There are other more direct ways to see this. For example if you try and use This behavior changed in the 5.0 SDK because we fixed a bug. Previously we were suppressing this diagnostic and that caused us to incorrectly treat Overall this scenario has a more fundamental problem: it's not specifying the fully set of references needed to resolve the exposed types here. Specifically the compiler is not being provided Microsoft.Azure.Cosmos.Direct.dll. The compiler does as much as it can to still function when it's missing references. For example if you expose methods where you’re missing references for the types of the methods and you never call a method with that name then the compiler will generally be able to tolerate the missing reference. So if the uses cases are right and just the right set of references are missing it will work out. The problem is the compiler makes no guarantees between versions though that we can tolerate the same set of missing references. Bug fixes, or even features can, force our hand here at considering defined members that we didn’t before and hence erroring because we can’t see all the types. In general my advice is to provide all the necessary references whenever possible. |
I believe this was fixed in V3 SDK (#1922) but never ported to V4 SDK (there were no new previews). If we compare the Nuget package of V3 from before and after the fix: And if you instead of using |
That does look like it should fix it. If there isn't a |
Also, if you try to use any V3 SDK previous to this fix, like |
We don't have any new preview release slated to be released at this point, I'll update this thread if this can be fixed soon. |
Hi, do we have a fix for this? Without PartitionKey methods like ReadItemAsync and DeleteItemAsync can't be used. Or am I missing something? Thanks |
You can reference the .Direct to remove the issue. More importantly, you should consider using the actual supported library, which has two years of features and bugfixes included relative to There will eventually be a released |
Thanks for the clarification! I'll use V3 then 🙂 |
Describe the bug
Receive the compiler error when trying to build netstandard 2.1 library referencing Azure.Cosmos version 4.0.0-preview3:
Error CS0012 The type 'PartitionKeyInternal' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Azure.Cosmos.Direct, Version=3.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
To Reproduce
Expected behavior
Build completes successfully.
Actual behavior
Build fails with compiler error CS0012
Environment summary
SDK Version: 4.0.0-preview3
OS Version: Windows 10 19042.804
VS Version: Visual Studio Community 2019 16.8.4
Additional context
This issue is described in EFCore repo in the context of the v3 SDK:
dotnet/efcore#22231
The workaround proposed by @jongio dotnet/efcore#22231 (comment) fixes this issue in the 4.0.0-preview3 SDK but should not be necessary.
The text was updated successfully, but these errors were encountered: