jspuij / Cortex.Net

State management like MobX for .NET and Blazor
https://jspuij.github.io/Cortex.Net.Docs
MIT License
81 stars 11 forks source link

The sample code throws an error: k__BackingField' is declared in another module and needs to be imported #58

Open pauldotknopf opened 3 years ago

pauldotknopf commented 3 years ago

The sample code from here: https://jspuij.github.io/Cortex.Net.Docs/pages/threading.html

Throws:

  Fody: An unhandled exception occurred:
Exception:
Member 'System.String <Testtt>k__BackingField' is declared in another module and needs to be imported
Type:
System.ArgumentException
StackTrace:
   at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 2227
   at Mono.Cecil.Cil.CodeReader.PatchRawCode(ByteBuffer buffer, Int32 code_size, CodeWriter writer) in C:\Code\Fody\cecil\Mono.Cecil.Cil\CodeReader.cs:line 585
   at Mono.Cecil.Cil.CodeReader.PatchRawMethodBody(MethodDefinition method, CodeWriter writer, Int32& code_size, MetadataToken& local_var_token) in C:\Code\Fody\cecil\Mono.Cecil.Cil\CodeReader.cs:line 487
   at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody(MethodDefinition method) in C:\Code\Fody\cecil\Mono.Cecil.Cil\CodeWriter.cs:line 73
   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method) in C:\Code\Fody\cecil\Mono.Cecil.Cil\CodeWriter.cs:line 49
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1639
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1631
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1445
   at Mono.Cecil.MetadataBuilder.AddTypes() in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1416
   at Mono.Cecil.MetadataBuilder.BuildTypes() in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1266
   at Mono.Cecil.MetadataBuilder.BuildModule() in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1036
   at Mono.Cecil.MetadataBuilder.BuildMetadata() in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 1006
   at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 144
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read) in C:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 971
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 143
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 119
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) in C:\Code\Fody\cecil\Mono.Cecil\AssemblyWriter.cs:line 78
   at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters) in C:\Code\Fody\cecil\Mono.Cecil\ModuleDefinition.cs:line 1160
   at InnerWeaver.WriteModule() in C:\projects\fody\FodyIsolated\ModuleWriter.cs:line 18
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 114
Source:
Mono.Cecil
TargetSite:
Mono.Cecil.MetadataToken LookupToken(Mono.Cecil.IMetadataTokenProvider)

If I remove = "World"; from the auto property, it works. It looks like it can't weave when there is a default value for auto properties.

jspuij commented 3 years ago

Thank you. I'll investigate.

jspuij commented 3 years ago

@pauldotknopf This is an interesting case because the error message that is happening is because of a dangling reference to the backing field in the constructor, when it is being initialized.

I'll see what I can do with this, but it is a bit intricate because it is an initial value, that should not trigger the setter.