k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
399 stars 33 forks source link

NoSuchCapabilityErrorImpl exception when building #194

Closed Lars-Sommer closed 1 year ago

Lars-Sommer commented 1 year ago

I have a small flutter project with several classes. The dart_json_mapper works fine on linux, but on a windows machine I cannot startup the project because of this exception: _NoSuchCapabilityErrorImpl (Requesting mirror on un-marked class,superclassof.Location) If I continue the execution, the same exception occurs on the next class.

I run flutter pub run build_runner watch --delete-conflicting-outputs to make sure the main.mapper.g.dart file is up to date.

This is my Location class:

import 'package:dart_json_mapper/dart_json_mapper.dart';

@JsonSerializable()
class Location {
  String? id;
  String? name;
  bool newsletter = false;
}

pubspec.yaml

dart_json_mapper: ^2.2.5+3
  dart_json_mapper_flutter: ^2.0.1

build.yaml

targets:
  $default:
    builders:
      dart_json_mapper:
        generate_for:
        # here should be listed entry point files having 'void main()' function
          - lib/main.dart

      # This part is needed to tell original reflectable builder to stay away
      # it overrides default options for reflectable builder to an **empty** set of files
      reflectable:
        generate_for:
          - no/files

Thanks!

k-paxian commented 1 year ago

Thanks for sharing. I'm sure we need more details to diagnose the issue. I'm doing all the development on windows, so feel free to prepare bare minimum project to reproduce the issue and we could start investigation.

Error text smells like reflectable issue, but we need to confirm that.

Lars-Sommer commented 1 year ago

Thanks alot for your answer 👍 I´ve created a new simple project, installed the automapper and tried it out. It works fine. I then spent the last 3 hours copying all the code and what not from my original project to this test project, hoping to find the cause. The projects are now alike, but unfortunately the error does not occur in the new project. So i´m pretty clueless about the problem right now 🤯 I´ll take a break and look at it with fresh eyes tomorrow.

k-paxian commented 1 year ago

Pay some attention to pubspec.lock, sometimes it helps wiping it out and have it fresh

Lars-Sommer commented 1 year ago

Good tip, thanks. I´ve tried deleting the pubspec.lock file, and then run flutter pub get to rebuild it. But the problem still persist.

Lars-Sommer commented 1 year ago

I copied the project 1:1 in a new folder. Starting the project in the new folder fixed the problem. I have absolutely no clue why this works 🤔