# RuntimeError: The ASGI application instance is not available.

- **ID:** `python/starlette-missing-app-instance`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

尝试在Starlette应用之外访问app实例，例如在导入时或测试中未正确设置。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **在应用上下文中访问app，例如通过request.app** (95% success)
   ```
   from starlette.requests import Request; async def my_endpoint(request: Request): app = request.app; return JSONResponse({'app': str(app)})
   ```
2. **在测试中使用TestClient时确保app已创建** (90% success)
   ```
   from starlette.testclient import TestClient; from main import app; client = TestClient(app); response = client.get('/')
   ```

## Dead Ends

- **在模块级别直接访问app对象** — app可能尚未创建或已被回收。 (80% fail)
- **使用全局变量存储app引用** — 多线程环境下可能导致竞态条件。 (70% fail)
