Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2de9b8

Browse files
committed
Fix getentryassembly
Codeplex issue:https://visualfsharp.codeplex.com/workitem/131 System.Reflection.Assembly.GetEntryAssembly() returns null if shadow copying is true, and the FSI assembly otherwise. Quite a few tools use GetEntryAssembly to get at FSI state, including some internal tools we use. They will break with the new FSI. Modified test2 to also verify that GetEntryAssembly() returns non-null. Added a bit more diagnostic output to test1 and test2 (changeset 1339032)
1 parent09e5eb5 commitd2de9b8

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

‎src/fsharp/fsi/fsi.fs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ type internal FsiEvaluationSession (argv:string[], inReader:TextReader, outWrite
23402340

23412341
// Mark the main thread as STAThread since it is a GUI thread
23422342
[<EntryPoint>]
2343-
[<STAThread()>]
2343+
[<STAThread()>]
23442344
[<LoaderOptimization(LoaderOptimization.MultiDomainHost)>]
23452345
letMainMain argv=
23462346
ignore argv
@@ -2369,11 +2369,12 @@ let MainMain argv =
23692369
fsi.Run()
23702370
#endif
23712371

2372-
if argv|> Array.exists(fun x-> x="/shadowcopyreferences"|| x="--shadowcopyreferences"|| x="/shadowcopyreferences+"|| x="--shadowcopyreferences+")then
2372+
letisShadowCopy x=(x="/shadowcopyreferences"|| x="--shadowcopyreferences"|| x="/shadowcopyreferences+"|| x="--shadowcopyreferences+")
2373+
if AppDomain.CurrentDomain.IsDefaultAppDomain()&& argv|> Array.exists isShadowCopythen
23732374
letsetupInformation= AppDomain.CurrentDomain.SetupInformation
23742375
setupInformation.ShadowCopyFiles<-"true"
23752376
lethelper= AppDomain.CreateDomain("FSI_Domain",null, setupInformation)
2376-
helper.DoCallBack(fun()-> evaluateSession())
2377+
helper.ExecuteAssemblyByName(Assembly.GetExecutingAssembly().GetName())|> ignore
23772378
else
23782379
evaluateSession()
23792380
0

‎tests/fsharp/core/fsi-shadowcopy/test1.fsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ let next = compiled 30000;;
2121
if next=falsethen
2222
printfn"Succeeded -- compile fail because file locked due to --shadowcopyreferences-"
2323
use os= System.IO.File.CreateText"test1.ok"
24-
os.Close();;
24+
os.Close()
25+
else
26+
printfn"Failed -- compile succeeded but should have failed due to file lock because of --shadowcopyReferences-. Suspect test error";;
27+
2528
#quit;;

‎tests/fsharp/core/fsi-shadowcopy/test2.fsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ let compiled wait =
99
c.WaitForExit(wait)|> ignore
1010
if c.ExitCode=0thentrueelsefalse;;
1111

12+
// Verify that System.Reflection.Assembly.GetEntryAssembly() does not return null
13+
// When GetEntryAssembly is called inside an appdomain, if the assembly wasn't started useng ExecuteAssembly
14+
// GetEntryAssembly returns a null. this check ensures the appdomain is started the right way.
15+
letverifyGetEntryAssembly=if System.Reflection.Assembly.GetEntryAssembly()=nullthenfalseelsetrue
16+
1217
// Build the library
1318
letfirst= compiled30000;;
14-
19+
1520
//reference it will not lock the assembly because FSI was started with --shadowCopyReferences+
1621
#r"Library1.dll";;
1722

@@ -20,6 +25,13 @@ let next = compiled 30000;;
2025
//compile will succeed because shadow copy is enabled
2126
if next=truethen
2227
printfn"Succeeded -- compile worked because file not locked due to --shadowcopyReferences+"
23-
use os= System.IO.File.CreateText"test2.ok"
24-
os.Close();;
28+
if verifyGetEntryAssemblythen
29+
printfn"Succeeded -- GetEntryAssembly() returned not null"
30+
use os= System.IO.File.CreateText"test2.ok"
31+
os.Close()
32+
else
33+
printfn"Failed -- GetEntryAssembly() returned null"
34+
else
35+
printfn"Failed -- compile failed because file was locked should not have been looked due to --shadowcopyReferences+";;
36+
2537
#quit;;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp