You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored and
KenM76
committed
v0.4.2: auto-provided Office interop aliases for .csx scripts
Implements FR_office_script_interop_alias.md in full. Fixes the CS0104
ambiguous-reference papercut that hit every Windows Office script:
`Range`, `Exception`, `Application`, `Style`, `Font`, `Action`, `Page`
collide between the auto-imported interop namespace and the BCL. `Range`
was the worst because modern C# added `System.Range` for slicing, so
the common idiom `Range used = xlSheet.UsedRange;` failed until each
author re-typed `using Xl = global::Microsoft.Office.Interop.Excel;` at
the top of every .csx.
Mechanism (picked option b from the FR, not option a):
- New `IComBridgePlugin.ScriptUsingAliases` contract member (default
empty, so non-Office plugins are zero-impact). Each Windows Office
plugin overrides to return its conventional two-letter alias body:
excel→Xl, word→Wd, powerpoint→Pp, outlook→Ol — all qualified to
global::Microsoft.Office.Interop.*.
- ScriptHost.RunAsync concatenates contributed aliases onto a single
preamble line at the top of the script source, preserves BOM +
encoding so PDB emit still works (CS8055-free), then passes the
combined stream to CSharpScript.Create.
- Diagnostic line/column spans in Roslyn compile errors are rewritten
back to the author's real source via a regex over the diagnostic
ToString(). Errors located inside the preamble itself are left
untouched so plugin-author bugs surface loudly instead of presenting
as "your script line 0."
Verified end-to-end:
- Positive: each of word/excel/powerpoint/outlook resolves Wd.Application,
Xl.Application, Pp.Application, Ol.MailItem with NO author-declared
alias.
- Negative: bare `Range` is still ambiguous CS0104 — we deliberately
did NOT win the bare-name race against System.Range.
- Line-number remap: the CS0104 from the negative test reports the
author's real line, not the +1 compiled line.
Mirrored to D:\Dev\ScripTree\lib\combridge\ and R:\ScripTree\lib\combridge\
per the CLAUDE.md deployment mandate; byte-sizes match the source
build (host 162304, Outlook.Mac DLL 30720 from v0.4.1).
Docs updated:
- LLM/scripting.md § Office namespace shadowing rewritten to lead with
the auto-alias and show the fully-qualify fallback.
- LLM/troubleshooting.md gains a dedicated CS0104 entry with the alias
table inline.
- FR_office_script_interop_alias.md stamped with implementation log
noting the option taken and verification results.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: LLM/troubleshooting.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,58 @@ the right section based on when the error fires.
6
6
7
7
## Build-time errors
8
8
9
+
### `error CS0104: 'Range' is an ambiguous reference between 'Microsoft.Office.Interop.Word.Range' and 'System.Range'` (or `Exception`, `Application`, `Style`, …)
10
+
11
+
**Symptom.** A `.csx` running under any Windows Office plugin
12
+
(`excel` / `word` / `powerpoint` / `outlook`) fails to compile with
13
+
CS0104 on a bare identifier the BCL and the Office interop namespace
14
+
both define. Most common offender is `Range` because modern C# added
15
+
`System.Range` for slicing syntax.
16
+
17
+
**Why.** The Office plugin's `ScriptUsings` imports the interop
18
+
namespace so authors can write `Application`, `Range`, etc. unqualified.
19
+
But that namespace also defines its own `Exception`, `Application`,
20
+
`Style`, `Action`, `Font`, `Range`, etc. that collide with `System.*`.
21
+
Roslyn refuses to pick one.
22
+
23
+
**Fix (v0.4.2+ — recommended).** Use the **auto-provided two-letter
24
+
alias** the plugin contributes to your script. No `using ... = ...`
25
+
declaration needed — it's already in scope:
26
+
27
+
```csharp
28
+
Xl.Rangeused=xlSheet.UsedRange; // not bare Range
29
+
Wd.Rangerng=wdDoc.Content;
30
+
catch (System.Exceptionex) { ... } // qualify the BCL side
0 commit comments