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

Cannot create an XmlSerializer of a type defined in a script #22859

Open
aelij opened this issue Oct 26, 2017 · 7 comments
Open

Cannot create an XmlSerializer of a type defined in a script #22859

aelij opened this issue Oct 26, 2017 · 7 comments
Assignees
Milestone

Comments

@aelij
Copy link
Contributor

aelij commented Oct 26, 2017

Version Used: 2.3.2 (VS 15.4)

Steps to Reproduce:

In C# Interactive:

#r "System.Xml"
class X { }
new System.Xml.Serialization.XmlSerializer(typeof(X))

Expected Behavior:
Return an XmlSerializer.

Actual Behavior:

The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)
  + System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(int, System.IntPtr)
  + Microsoft.Win32.Fusion.ReadCache(System.Collections.ArrayList, string, uint)
  + System.Reflection.RuntimeAssembly.EnumerateCache(System.Reflection.AssemblyName)
  + System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(System.Reflection.AssemblyName, System.Security.Policy.Evidence, ref System.Threading.StackCrawlMark)
  + System.Reflection.Assembly.LoadWithPartialName(string, System.Security.Policy.Evidence)
  + System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly(System.Type, string, out System.Xml.Serialization.XmlSerializerImplementation)
  + System.Xml.Serialization.XmlSerializer..ctor(System.Type, string)
  + System.Xml.Serialization.XmlSerializer..ctor(System.Type)

Analysis:
I believe the issue is that generated assembly name for script assemblies contains an invalid character for the file system (#), and when the serializer attempts to load a serialization assembly, it fails.

_assemblyNamePrefix = s_globalAssemblyNamePrefix + "#" + Interlocked.Increment(ref s_engineIdDispenser).ToString();

@jcouv
Copy link
Member

jcouv commented Oct 27, 2017

Tagging @tmat

@andrew-vdb
Copy link

Any workaround for this?

@tmat
Copy link
Member

tmat commented Sep 2, 2019

I believe the issue is that generated assembly name for script assemblies contains an invalid character for the file system (#)

# is perfectly valid file name character.

@aelij
Copy link
Contributor Author

aelij commented Sep 2, 2019

@tmat I was mistaken, the problem was the * in the assembly name:

s_globalAssemblyNamePrefix = "\u211B*" + Guid.NewGuid().ToString();

I've added a test to the PR.

@tmat
Copy link
Member

tmat commented Sep 2, 2019

This is a bug in XmlSerializer. I'm fine with implementing a workaround and omitting * from the assembly name since it's unlikely that the issue in XmlSerializer in .NET Framework will be fixed.

@tmat
Copy link
Member

tmat commented Sep 3, 2019

What's the scenario for which XML serialization of types defined in a script is needed?

@uholeschak
Copy link

Is there already a workaround for this?

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

Successfully merging a pull request may close this issue.

6 participants