pulumi / pulumi-dotnet

.NET support for Pulumi
Apache License 2.0
28 stars 25 forks source link

System.MissingMethodException: Method not found: 'Void Pulumi.ProviderResource..ctor'... #317

Closed Muchaszewski closed 3 months ago

Muchaszewski commented 3 months ago

What happened?

Instantiate new provider from code

    var cloudflareProvider = new Cloudflare.Provider("cloudflare-provider", new ProviderArgs 
    {
        ApiToken = ApiToken
    });

or

        Provider = new MongodbAtlasProvider("mongodbatlas", new ProviderArgs
        {
            PublicKey = PublicApiKey,
            PrivateKey = PrivateApiKey
        });

This code worked ~3 months ago, and I did change nothing in my code base. Now I could finally get back to this deployment and I encountered the following issue on ALL providers.

 error: Running program 'project\bin\Debug\net6.0\vinode-deployment.dll' failed with an unhandled exception:
    System.MissingMethodException: Method not found: 'Void Pulumi.ProviderResource..ctor(System.String, System.String, Pulumi.ResourceArgs, Pulumi.CustomResourceOptions)'.
       at new Pulumi.Cloudflare.Provider(string name, ProviderArgs args, CustomResourceOptions options)
       at new Project.Providers.CloudflareConfig(Config config) in project/Providers/Cloudflare.cs:line 18

Right now, after running this code for all providers, I get this error.

I tried:

The only thing that helps is copy-pasting the decompiled code, and implementing it manually and using that instead. But this workaround is messy and I wish I would not have to do that.

Example

    var cloudflareProvider = new Cloudflare.Provider("cloudflare-provider", new ProviderArgs 
    {
        // You might need to configure the Cloudflare provider by setting your Cloudflare API token.
        ApiToken = "<YOUR_CLOUDFLARE_API_TOKEN>" // Replace this with your actual API token.
    });

or

        Provider = new MongodbAtlasProvider("mongodbatlas", new ProviderArgs
        {
            PublicKey = PublicApiKey,
            PrivateKey = PrivateApiKey
        });

Exception

 error: Running program 'project\bin\Debug\net6.0\vinode-deployment.dll' failed with an unhandled exception:
    System.MissingMethodException: Method not found: 'Void Pulumi.ProviderResource..ctor(System.String, System.String, Pulumi.ResourceArgs, Pulumi.CustomResourceOptions)'.
       at new Pulumi.Cloudflare.Provider(string name, ProviderArgs args, CustomResourceOptions options)
       at new Project.Providers.CloudflareConfig(Config config) in project/Providers/Cloudflare.cs:line 18

Output of pulumi about

CLI
Version      3.128.0
Go Version   go1.22.5
Go Compiler  gc

Plugins
KIND      NAME          VERSION
resource  cloudflare    5.36.0
language  dotnet        unknown
resource  kubernetes    4.16.0
resource  linode        4.24.0
resource  mongodbatlas  3.16.7

Host     
OS       Microsoft Windows 10 Pro
Version  10.0.19045 Build 19045
Arch     x86_64

This project is written in dotnet: executable='C:\Program Files\dotnet\dotnet.exe' version='8.0.303'

Current Stack: organization/project-deployment/dev

TYPE                                                        URN
pulumi:pulumi:Stack                                         urn:pulumi:dev::project-deployment::pulumi:pulumi:Stack::project-deployment-dev
pulumi:providers:mongodbatlas                               urn:pulumi:dev::project-deployment::pulumi:providers:mongodbatlas::mongodbatlas
pulumi:providers:cloudflare                                 urn:pulumi:dev::project-deployment::pulumi:providers:cloudflare::cloudflare
pulumi:providers:linode                                     urn:pulumi:dev::project-deployment::pulumi:providers:linode::linode
mongodbatlas:index/project:Project                          urn:pulumi:dev::project-deployment::mongodbatlas:index/project:Project::atlas-project-project
linode:index/lkeCluster:LkeCluster                          urn:pulumi:dev::project-deployment::linode:index/lkeCluster:LkeCluster::project-lke-cluster
mongodbatlas:index/projectIpAccessList:ProjectIpAccessList  urn:pulumi:dev::project-deployment::mongodbatlas:index/projectIpAccessList:ProjectIpAccessList::atlas-project-ip-access-list
mongodbatlas:index/databaseUser:DatabaseUser                urn:pulumi:dev::project-deployment::mongodbatlas:index/databaseUser:DatabaseUser::atlas-project-admin
mongodbatlas:index/serverlessInstance:ServerlessInstance    urn:pulumi:dev::project-deployment::mongodbatlas:index/serverlessInstance:ServerlessInstance::atlas-project-serverless
pulumi:providers:kubernetes                                 urn:pulumi:dev::project-deployment::pulumi:providers:kubernetes::kubernetes
kubernetes:core/v1:ServiceAccount                           urn:pulumi:dev::project-deployment::kubernetes:core/v1:ServiceAccount::traefik-account
kubernetes:core/v1:Service                                  urn:pulumi:dev::project-deployment::kubernetes:core/v1:Service::traefik
kubernetes:core/v1:Secret                                   urn:pulumi:dev::project-deployment::kubernetes:core/v1:Secret::docker-cfg
kubernetes:core/v1:Service                                  urn:pulumi:dev::project-deployment::kubernetes:core/v1:Service::api-gateway-service
kubernetes:rbac.authorization.k8s.io/v1:ClusterRole         urn:pulumi:dev::project-deployment::kubernetes:rbac.authorization.k8s.io/v1:ClusterRole::traefik-role
kubernetes:rbac.authorization.k8s.io/v1:ClusterRoleBinding  urn:pulumi:dev::project-deployment::kubernetes:rbac.authorization.k8s.io/v1:ClusterRoleBinding::traefik-role-binding
kubernetes:apps/v1:Deployment                               urn:pulumi:dev::project-deployment::kubernetes:apps/v1:Deployment::traefik
cloudflare:index/record:Record                              urn:pulumi:dev::project-deployment::cloudflare:index/record:Record::dev-api.project.io
kubernetes:core/v1:Pod                                      urn:pulumi:dev::project-deployment::kubernetes:core/v1:Pod::api-gateway-pod
kubernetes:networking.k8s.io/v1:Ingress                     urn:pulumi:dev::project-deployment::kubernetes:networking.k8s.io/v1:Ingress::api-gateway-ingress

Found no pending operations associated with dev

Backend
Name           DESKTOP-0K3LPFN
URL            file://~
User           DESKTOP-0K3LPFN\Work
Organizations
Token type     personal

Dependencies:
NAME                 VERSION
Newtonsoft.Json      13.0.3
Pulumi               3.66.0
Pulumi.Cloudflare    5.36.0
Pulumi.Kubernetes    4.16.0
Pulumi.Linode        4.24.0
Pulumi.Mongodbatlas  3.16.7

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

Muchaszewski commented 3 months ago

Note, that after replacing all providers like that there are further errors as if the DLLs with plugins/modules were not loaded at all.

Video with debugger attached on how the issue looks, step into and step over generate the same result:

https://github.com/user-attachments/assets/36cd252f-7796-4c97-921d-68810bf71ca0

Compilation result folder has all the DLLs, and they all contain all correct definitions (after decompilation)

Image

Zaid-Ajaj commented 3 months ago

Hi there @Muchaszewski thanks a lot for filing the issue! :pray: any chance you could try the reverting Pulumi from v3.66.0 to v3.65.0 or removing the Pulumi nuget package entirely? (since it is a dependency of the providers)

We did add a new optional parameter for the constructor of Provider:

public ProviderResource(
            string package,
            string name,
            ResourceArgs args,
            CustomResourceOptions? options = null)

became:

public ProviderResource(
    string package,
    string name,
    ResourceArgs args,
    CustomResourceOptions? options = null,
    RegisterPackageRequest? registerPackageRequest = null)

Which I assumed to be non a breaking change (the new parameter is optional) but it looks like existing .NET SDKs built with older versions of Pulumi looks for that exact parameter, regardless of optionalness (not binary compatible)

I can repro using the provider from Pulumi.Random v4.16.3 (built with Pulumi v.3.64.0) and it gives the same error

Zaid-Ajaj commented 3 months ago

Hi @Muchaszewski version 3.66.1 has been published and I've tested that the issue no longer appears with providers, invokes or resources. Please give it a try and let us know if you encounter any issues.

Muchaszewski commented 3 months ago

The error is gone! Thank you for your fast response and for fixing the issue!