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

What the check File.WriteAllBytes("testasm.dll", data) in tests? #30

Closed
rstm-sf opened this issue Oct 4, 2020 · 7 comments
Closed

What the check File.WriteAllBytes("testasm.dll", data) in tests? #30

rstm-sf opened this issue Oct 4, 2020 · 7 comments

Comments

@rstm-sf
Copy link

rstm-sf commented Oct 4, 2020

Hello!

I am thinking to add github actions and, accordingly, restore tests. I have updated the nuget packages and upgraded to netcoreapp 3.1. But the chair ran into the fact that my tests fall in this place

File.WriteAllBytes("testasm.dll", data);

With the following error

  Message: 
    System.IO.IOException : The process cannot access the file '.\XamlX\tests\CecilNetstandardTests\bin\Debug\netcoreapp3.1\testasm.dll' because it is being used by another process.
  Stack Trace: 
    FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
    FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
    FileStream.ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
    FileStream.ctor(String path, FileMode mode, FileAccess access, FileShare share)
    File.InternalWriteAllBytes(String path, Byte[] bytes)
    File.WriteAllBytes(String path, Byte[] bytes)
    CompilerTestBase.Compile(String xaml) line 75
    BasicCompilerTests.Compiler_Should_Compile_Simple_Xaml(Boolean populate) line 27

If I comment out, most of the tests pass (I don't think those test pairs are related to this). What this check?

P.S. If necessary, you can try, for example, using System.IO.Abstractions.TestingHelpers, writing something like this

@kekekeks
Copy link
Owner

kekekeks commented Oct 5, 2020

That's weird, that line is inside a lock, so there shouldn't be any concurrent writes to that file. The line itself can be safely removed, it's here for convenience purposes so one could inspect the generated assembly with disassembler right away.

@rstm-sf
Copy link
Author

rstm-sf commented Oct 11, 2020

This happens after running tests for net47. If we remove the build after that, for example with git clean -xdf, then the tests for netcoreapp3.1 start to pass

As far as net47 goes, it drops there at this

var createCb = Expression.Lambda<Func<IServiceProvider, object>>(
Expression.Convert(Expression.Call(
created.GetMethod("Build"), isp), typeof(object)), isp).Compile();

($exception).FusionLog from VS debugger
=== Pre-bind state information ===
LOG: DisplayName = CecilNetstandardTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\TestPlatform\testhost.x86.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/CecilNetstandardTests.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/CecilNetstandardTests/CecilNetstandardTests.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/Extensions/CecilNetstandardTests.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/Extensions/CecilNetstandardTests/CecilNetstandardTests.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/CecilNetstandardTests.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/CecilNetstandardTests/CecilNetstandardTests.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/Extensions/CecilNetstandardTests.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/TestPlatform/Extensions/CecilNetstandardTests/CecilNetstandardTests.EXE.

It seems that this is a VS problem and it is somewhat similar to this question

@kekekeks
Copy link
Owner

What happens if you change the file extension from dll to bin?

@rstm-sf
Copy link
Author

rstm-sf commented Oct 11, 2020

Extension change helped 🤨

@rstm-sf
Copy link
Author

rstm-sf commented Oct 11, 2020

But it still seems to me that it is better to delete it, since it does not really carry anything, and the load on the storage exists

@kekekeks
Copy link
Owner

kekekeks commented Oct 12, 2020

Should probably wrap it inside #if or something. It was really helpful for debugging at the time.

@rstm-sf
Copy link
Author

rstm-sf commented Oct 12, 2020

Ok, I added an extra condition on build for this in #31

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