While I was able to get my C# code running in the browser as WebAssembly, I get errors like this when trying to run any (vitest) unit tests that load the module that initializes .NET:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: The URL must be of scheme file
❯ Object.fileURLToPath node:internal/url:1393:11
❯ src/_framework/dotnet.native.js:8:1475
❯ processTicksAndRejections node:internal/process/task_queues:95:5
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_INVALID_URL_SCHEME' }
This error originated in "src/[...].test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
Based on console logs, it is triggered by the standard initialization statement:
import { dotnet } from '_framework/dotnet.js';
...
setTimeout(async () => {
console.log('*** Initializing .NET');
try {
const { setModuleImports, getAssemblyExports, getConfig, runMain }
= await dotnet.withApplicationArguments('start').create();
...
It's important to also be able to use C# code in unit tests, so how do I fix this?
Note: I have a catch block which should have caught any exceptions, but my console.error does not appear. And the code that causes the error is minified so I can't read it.