Failed to emit module 'projectname'

hmmm just stumbled on something that has be a bit ???
Changed a few lines of code in multiple projects in same solution and the could not build the TinyCLR Library all the other projects depended on.

Had me chasing tail for a bit!! As didnt keep track of changes and OF COURSE I have no Version Control set up as … well…

Anyway, found it, and it turns out if I reproduce same code in a NEW Blank TinyCLR Library v1.0.0 TinyCLR.Core (referenced only), VS2019 v16.2.5 I get same error
Can anyone else reproduce?

namespace TinyCLRClassLibrary1
{
public class Class1
{
private void RemoveCRLF(string text)
{
string aString = “Weeee”;
byte bBytes = new byte[4] {1,2,3,4 };

       foreach (byte b in  bBytes)
       { }

       foreach (char c in aString) /* This is what cause emit error */
       { }
   }

}
}

Build and get Error
"CS7038 Failed to emit module ‘TinyCLRClassLibrary1’

Remark out the foreach(char … and builds
Am I missing something obvious?

2 Likes

Try a simple for-loop and use aString[index] instead.

2 Likes

Yep lots of options. Thanks!

Main reason for posting it was to see if this is an issue with TinyCLR libs?
Think I have found a few other strange things with some FIelds and Properties using Reflection relating to ‘String’ Types.
Seeing some weird Getter Methods on String.Length and String.Empty and others while trying to implement a JSon DeSerialiser back into POCO’s …
Im starting to think its related and just wanted to get peoples feedback. Its a non common error for this line of code, just to cause that.

If I remember right from when I last looked into this it is because string does not implement IEnumerable or the pattern expected by foreach. We have an issue open to look into that in the future.

2 Likes