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

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

Open
pauldotknopf opened this issue May 22, 2021 · 2 comments
Assignees

Comments

@pauldotknopf
Copy link

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.

@pauldotknopf pauldotknopf changed the title The sample code throws an error The sample code throws an error: k__BackingField' is declared in another module and needs to be imported May 22, 2021
@jspuij
Copy link
Owner

jspuij commented May 26, 2021

Thank you. I'll investigate.

@jspuij jspuij self-assigned this May 26, 2021
@jspuij
Copy link
Owner

jspuij commented May 26, 2021

@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.

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

No branches or pull requests

2 participants